28👍
See https://code.djangoproject.com/ticket/3400 . It works ok in django 1.3 🙂
class Room(models.Model):
house = models.ForeignKey(House)
def __unicode__(self):
return self.house.town.name
class Booking(models.Model):
room = models.ForeignKey(Room)
def __unicode__(self):
return self.room.house.town.name
class BookingOpts(admin.ModelAdmin):
list_filter = ('room__house__town',)
raw_id_admin = ('room', )
admin.site.register(Town)
admin.site.register(House)
admin.site.register(Room)
admin.site.register(Booking, BookingOpts)
👤luc
1👍
I have found and tested following solution:
http://www.djangosnippets.org/snippets/1911/
It works with ForeignKeys, but it doesn’t work with ManyToMany relations.
- [Django]-How do I restrict foreign keys choices to related objects only in django
- [Django]-OSQA vs. Askbot?
- [Django]-Received "ValueError: Found wrong number (0) of constraints for …" during Django migration
0👍
I ran into the same problem and really needed a solution. I have a workaround that lets you create a filter on a FK related model property. You can even traverse more than one FK relationship. It creates a new FilterSpec subclass that subclasses the default RelatedFilterSpec used to give you a filter on a ForeignKey field.
- [Django]-How to create an empty queryset and to add objects manually in django
- [Django]-Django: How to create a model dynamically just for testing
- [Django]-Form field description in django admin
Source:stackexchange.com