title: How to automatically update a field depending on the user who changed it in Django?
body: <h3>Context:</h3>
  
  <p>In the Blog part of page any registered User can post, but all posts that are from non superuser accounts have to be approved by an admin on the Admin page where I registered the model as well.
  This functions as intended.</p>
  
  <h3>My question:</h3>
  
  <p>How can I make it so that if a Blog Post gets updated by a superuser(doesn't matter what kind of a change for example: when admin opens one single post and adds in a further text in the body of the post, or deletes some part of a text because it seems malicious or fake), that it is automatically approved(The field approved gets then set to TRUE)?
  I already thought of adding a further field in the model called changed_by and have it initially null.</p>
  
  <h3>Code:</h3>
  
  <p>blog/models.py</p>
  
  <pre><code>from django.db import models
  from django.utils import timezone
  from django.contrib.auth.models import User
  from django.urls import reverse
  
  
  class BlogPost(models.Model):
      title = models.CharField(max_length=100)
      content = models.TextField()
      date_posted = models.DateTimeField(default=timezone.now)
      author = models.ForeignKey(User, on_delete=models.CASCADE)
      approved = models.BooleanField(default=False)
      changed_by = models.ForeignKey(User, default=None) # I am planning to use this but how?
  
      def __str__(self):
          return self.title
  
      def get_absolute_url(self):
          return reverse('blogPost-detail', kwargs={'pk': self.pk})
  </code></pre>
  
  <p>blog/admin.py</p>
  
  <pre><code>from django.contrib import admin
  from .models import BlogPost
  
  
  def approve_multiple_posts(modeladmin, request, queryset):
      for blogPost in queryset:
          if blogPost.approved:
              blogPost.approved = False
          else:
              blogPost.approved = True
          blogPost.save()
  
  
  approve_multiple_posts.short_description = 'Change approval status'
  
  
  class PostAdmin(admin.ModelAdmin):
      list_display = ['title', 'author', 'date_posted', 'approved']
      actions = [approve_multiple_posts, ]
  
  
  admin.site.register(BlogPost, PostAdmin)
  </code></pre>
  
  <p>blog/views.py</p>
  
  <pre><code>from django.shortcuts import render, get_object_or_404
  from django.contrib.auth.mixins import LoginRequiredMixin, UserPassesTestMixin
  from django.contrib.auth.models import User
  from .models import BlogPost
  from django.views.generic import (
      ListView,
      DetailView,
      CreateView,
      UpdateView,
      DeleteView
  )
  
  
  def blog(request):
      context = {
          'blogPosts': BlogPost.objects.all()
      }
      return render(request, 'blog/blog.html', context)
  
  
  class PostListView(ListView):
      model = BlogPost
      template_name = 'blog/blog.html'
      context_object_name = 'blogPosts'
      ordering = ['-date_posted']
      paginate_by = 5
  
      def get_queryset(self):
          return BlogPost.objects.filter(approved=True).order_by('-date_posted')
  
  
  class UserPostListView(ListView):
      model = BlogPost
      template_name = 'blog/user_blogPosts.html'
      context_object_name = 'blogPosts'
      paginate_by = 5
  
      def get_queryset(self):
          user = get_object_or_404(User, username=self.kwargs.get('username'))
          return BlogPost.objects.filter(author=user, approved=True).order_by('-date_posted')
  
  
  class PostDetailView(DetailView):
      model = BlogPost
  
  
  class PostCreateView(LoginRequiredMixin, CreateView):
      model = BlogPost
      fields = ['title', 'content']
  
      def form_valid(self, form):
          form.instance.author = self.request.user
          if self.request.user.is_superuser:
              form.instance.approved = True
          return super().form_valid(form)
  
  
  class PostUpdateView(LoginRequiredMixin, UserPassesTestMixin, UpdateView):
      model = BlogPost
      fields = ['title', 'content']
  
      def form_valid(self, form):
          form.instance.author = self.request.user
          return super().form_valid(form)
  
      def test_func(self):
          blog_post = self.get_object()
          if self.request.user == blog_post.author:
              return True
          return False
  
  
  class PostDeleteView(LoginRequiredMixin, UserPassesTestMixin, DeleteView):
      model = BlogPost
      success_url = '/blog'
  
      def test_func(self):
          blog_post = self.get_object()
          if self.request.user == blog_post.author:
              return True
          return False
  </code></pre>
  
  <p>I would appreciate any help/suggestions you have! Thanks</p>