Django admin, InLineForm and many2many fields

19 views
Skip to first unread message

Karim

unread,
Feb 9, 2016, 6:30:37 AM2/9/16
to Django Users
Hello everyone, I have a problem and I don't understand how to solve it.

I have a simple model:

Supplier(models.Model):
    organization = models.CharField(..)
    location = models.ManyToManyfield(Location, blank=True)

Location(models.Model):
    address = models.CharField(..)
    active = models.BooleanField(default=True)

I created the inlineform to use in the supplier django-admin page:

class LocationInLineForm(admin.TabularInLine):
    model = Supplier.Location.through

I would like to show the records in the inlineform based on the supplier page in django admin. An administrator in the django admin click on a supplier and the inlineform must shows only the location owned by the selected supplier.

- I don't understand which method override (get_queryset? formfield_for_foreignkey?)
- I don't know how to get the is of the supplier loaded in the django admin.

I would like also filter the location based on the active boolean field. Is possible to do that? 

Thanks


--
Karim N. Gorjux
Reply all
Reply to author
Forward
0 new messages