#24395: Cannot reference FK relation from inline ModelForm.save()
---------------------------------+-------------------------------------
Reporter: Starou | Owner: nobody
Type: Bug | Status: new
Component: Forms | Version: 1.8alpha1
Severity: Release blocker | Resolution:
Keywords: | Triage Stage: Accepted
Has patch: 0 | Needs documentation: 0
Needs tests: 0 | Patch needs improvement: 0
Easy pickings: 0 | UI/UX: 0
---------------------------------+-------------------------------------
Comment (by Starou):
Replying to [comment:3 Starou]:
>
> Using the following "patch" fixing the problem apparently:
>
> {{{
> - setattr(form.instance, self.fk.get_attname(), fk_value)
> + setattr(form.instance, self.fk.get_attname(), self.instance)
> }}}
>
That was a mistake because we'll get an `Author` instance in a
`Book.author_id` field which is casted in an integer later. For some
reason this only breaks if `self.instance` isn't saved in the database.
And of course - by design - we cannot do what was in my mind:
{{{
setattr(form.instance, self.fk.name, self.instance)
}}}
Without raising an exception with an unsaved object:
{{{
ValueError: Cannot assign "<Poet: >": "Poet" instance isn't saved in the
database.
}}}
So I'll stick with my first idea of updating the forms references in the
inline_formset.save() method:
https://github.com/Starou/django/compare/ticket_24395
--
Ticket URL: <https://code.djangoproject.com/ticket/24395#comment:4>
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 [email protected].
To post to this group, send email to [email protected].
To view this discussion on the web visit
https://groups.google.com/d/msgid/django-updates/064.2c9c0e23d0643a63537b579792fe756a%40djangoproject.com.
For more options, visit https://groups.google.com/d/optout.