How to show ForeignKey attributes in Django Admin

I am trying to show details of the foreign key in my Django admin. In my case I have a class Category with user in it and a class SubCategory with foreign key with the class Category. In my admin I want to show the user of each class SubCategory

Here is the example:

class Category(models.Model):
    user = models.ForeignKey(settings.AUTH_USER_MODEL, on_delete=models.CASCADE)

class SubCategory(models.Model):
    category= models.ForeignKey(Category, on_delete=models.CASCADE, related_name='SubCategory')

Here is the admin:

class CategoryAdmin(admin.ModelAdmin):
    list_display = ['user']
    list_filter = ['user']

class SubCategoryAdmin(admin.ModelAdmin):
    list_display = ['id','category']

My question

How can I filter the SubCategory by the user which is an attribute of the foreign key?

Back to Top