Monday, November 18, 2013

Filter ForeignKey values in model's admin view

Hi

I've got two Django models: Contact and Group, where Group has two fields: contact and contact_primary linked to Contact. Like this:

class Group(models.Model):      name = models.CharField(max_length=200)      contacts = models.ManyToManyField(Contact)      contact_primary = models.ForeignKey(Contact)

In the admin interface I can select a number of Contacts for the contacts field and then I want to see only these selected contacts in the contact_primary dropdown. Not necessarily immediately but definitely on subsequent admin view reloads. As it is now I can see all my Contacts, whether they're selected in the ManyToMany field or not.

How can I restrict the Contacts displayed for contact_primary only to those selected in contacts?

Thanks!

Michal

0 Comments:

Post a Comment

Subscribe to Post Comments [Atom]

<< Home


Real Estate