python - Attach User to Django ModelForm / FormView after submit -
I have a form VVS CBV (shows model form) which is working fine. However, now when I save it to the database, I want to add the "created" attribute in the form. This "created" field should be the current, logged-in user, who has filled out the form.
I have tried to delay the form.save () , Request.user
and then save everything ... but the page itself Redirects to, and the model data is not added. idea?
Relevant models.py :
contextual views.py :
class PostEventView (form view): Form_class = EventForm template_name = "event-submit.html" def form_valid (self, form): form = form.save (commit = False) Form.created_by = self.reated.user form.save () messages.success (self. Thank you for taking the time to add this opportunity! ') HttpResponseRedirect (reverse_logie (' single_envent ', Kwargs = {' slug ': form.slug}))
< / Pre>Thoughts?
credited to inform Danil Rosesman that I have forgotten ModelForm
There was an idea after adding this area, and I forgot excluded
as a result of my template {{form.non_field_errors}}
was also present, which was explained That's why I do not see a verification error
Comments
Post a Comment