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 :

class events (models.Model): title = model.ccarfield (max_length = 255) submit_det = models .DateField (auto_now = true, verbose_name = 'date submitted') by built_by = model. Phoenis (user) event_date = models.DateField ()

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 de> exclude = ['Created'] from my 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

Popular posts from this blog

java - Can't add JTree to JPanel of a JInternalFrame -

javascript - data.match(var) not working it seems -

javascript - How can I pause a jQuery .each() loop, while waiting for user input? -