gulrtosk
unread,Mar 1, 2012, 11:24:45 AM3/1/12Sign in to reply to author
Sign in to forward
You do not have permission to delete messages in this group
Either email addresses are anonymous for this group or you need the view member email addresses permission to view the original message
to django...@googlegroups.com
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