Hello list,
through trial and error I discovered that it isn't required to pass the foreign key form field post data to the constructor of an inline form set. Django will fill it in automatically by looking at the primary key of the 'instance=' given. So I figured I might as well exclude the hidden FK field from the form:
class Group(models.Model):
interest = models.CharField(max_length=100)
class Member(models.Model):
name = models.CharField(max_length=100)
group = models.ForeignKey(Group)
MemberFormSet = inlineformset_factory(Group, Member, exclude=('group',))
The 'exclude=' instruction is ignored and the form is printed the same as without 'exclude=('group',)'. This is odd, since the FKs aren't strictly required in the form set: if you pass post data *with* foreign key fields to the constructor MemberFormSet(), Django will use it for validation, but if you don't pass them, it's fine too, because Django will simply use the instance to fill them in automatically.
So, how can I exclude my 'group' foreign keys from the printed form set?
Thank you and cheers, glts
--
You received this message because you are subscribed to the Google Groups "Django users" group.
To view this discussion on the web visit https://groups.google.com/d/msg/django-users/-/msqQh54-X5oJ.
To post to this group, send email to django-users@googlegroups.com.
To unsubscribe from this group, send email to django-users+unsubscribe@googlegroups.com.
For more options, visit this group at http://groups.google.com/group/django-users?hl=en.
Subscribe to:
Post Comments (Atom)
No comments:
Post a Comment