#21967: ModelFormMixin have extra logic in get_form_kwargs that crash view ---------------------------------+----------------------------------------- Reporter: | Owner: nobody lagovas.lagovas@… | Status: new Type: Bug | Version: 1.6 Component: Generic views | Keywords: generic edit ModelFormMixin Severity: Normal | Has patch: 0 Triage Stage: Unreviewed | UI/UX: 0 Easy pickings: 0 | ---------------------------------+----------------------------------------- When view inherit FormView and ModelFormMixin, have correct form_class and model fields, view will crash with AttributeError at / 'AddNoteView' object has no attribute 'object'
in this code: {{{ class ModelFormMixin: .... def get_form_kwargs(self): """ Returns the keyword arguments for instantiating the form. """ kwargs = super(ModelFormMixin, self).get_form_kwargs() kwargs.update({'instance': self.object}) return kwargs }}} It's due to accessing to self.object before form.save(). Even in get request, when object can't be exist. To check this you need inherit from FormView and ModelFormMixin: class AddNoteView(FormView, ModelFormMixin): template_name = 'notes.html' form_class = NoteForm success_url = reverse_lazy('index') model = Note -- Ticket URL: <https://code.djangoproject.com/ticket/21967> Django <https://code.djangoproject.com/> The Web framework for perfectionists with deadlines. -- You received this message because you are subscribed to the Google Groups "Django updates" group. To unsubscribe from this group and stop receiving emails from it, send an email to django-updates+unsubscr...@googlegroups.com. To post to this group, send email to django-updates@googlegroups.com. To view this discussion on the web visit https://groups.google.com/d/msgid/django-updates/068.5d22eb1cce6f11ca2869244bb09abfff%40djangoproject.com. For more options, visit https://groups.google.com/groups/opt_out.