Django authentication and social-sign on with django-allauth

How to set the article creator in the form of a Class-Based View

Want more?

This lesson for enrolled students only. Join the course to unlock it!

You can see the code changes implemented in this lecture below.

If you have purchased the course in a different platform, you still have access to the code changes per lecture here on Teclado. The lecture video and lecture notes remain locked.
Join course for $15

Modified files

app/views.py
--- 
+++ 
@@ -1,3 +1,5 @@
+from django.forms.models import BaseModelForm
+from django.http import HttpResponse
 from django.shortcuts import render
 from django.urls import reverse_lazy
 from django.views.generic import (
@@ -22,6 +24,10 @@
     fields = ["title", "status", "content", "twitter_post"]
     success_url = reverse_lazy("home")

+    def form_valid(self, form: BaseModelForm) -> HttpResponse:
+        form.instance.creator = self.request.user
+        return super().form_valid(form)
+

 class ArticleUpdateView(UpdateView):
     template_name = "app/article_update.html"