Search
 
SCRIPT & CODE EXAMPLE
 
CODE EXAMPLE FOR PYTHON

how to form .cleaned data in class based views in django

from django.contrib.auth.mixins import LoginRequiredMixin
from django.views.generic.edit import CreateView
from myapp.models import Author

class AuthorCreateView(LoginRequiredMixin, CreateView):
    model = Author
    fields = ['name']

    def form_valid(self, form):
        form.instance.created_by = self.request.user
        return super().form_valid(form)
Source by docs.djangoproject.com #
 
PREVIOUS NEXT
Tagged: #form #data #class #based #views #django
ADD COMMENT
Topic
Name
5+5 =