I have two models, Attribute and Variant. Variant has a FK to Attribute. From the admin screen, when looking at an Attribute entry row (or the edit view for a single Attribute entry), I want to be able to click on a link 'show variants for attribute' which will take me on a the 'standard' view for Variant objects, but filtered to only show Variants for that Attribute.
I have been looking on the docs and found how to make filters on the sidebar e.g for dates etc, but not for the above scenario. Is this included in the standard documentation?
If this is not possible by default, what steps do I need to take to achieve this? I use Django 1.8.7
What you can do in the admin view is this:
class LocationDayAdmin(admin.ModelAdmin):
list_display = ('id', 'show_variants' )
def show_variants(self, obj):
return "<a href='/admin/<package>/variants/attribute__id__exact=" + str(obj.id) + "'>show variants</a>"
show_variants.allow_tags = True
Be sure that you have list_filter = ('attribute',)
in your AttributeAdmin