2

Seems like this'd be obvious - maybe it is... how can I put related_name into the admin?

If I have

class A(Model):
   whatever

class B(Model):
   a = ForeignKey(A, related_name='bs')

In the admin for B, 'a' shows up nicely. In the admin for A, how can I make the list 'bs' show up? I don't need to support inline editing, and the normal way of doing this (TabularInline) also shows more items in the 'bs' list than actually exist. Ideally, it would just show a list of hyperlinks to the relevant B objects...

Colin
  • 3,670
  • 1
  • 25
  • 36
  • Possible duplicate of [How to I show a list of ForeignKey reverse lookups in the DJango admin interface?](http://stackoverflow.com/questions/16070809/how-to-i-show-a-list-of-foreignkey-reverse-lookups-in-the-django-admin-interface) – Reto Aebersold Oct 28 '15 at 19:47
  • Do you mean how to show the list in the list display, or in the object view ? – karthikr Oct 28 '15 at 19:48
  • Is the inline model method the only way? I'm gonna have to hack that a bunch to get what I want - just a list of hyperlinks to the relevant B objects, for only the B objects that exist in the set. – Colin Oct 28 '15 at 20:01
  • @karthikr: nope. In the admin page for some A model, I want to show the B models that this A is related to, and only them. Ideally, with no edit, but with each as a hyperlink to the admin page for the appropriate B. – Colin Oct 28 '15 at 20:03

1 Answers1

1

In edit and new object view, you can show related records with InlineModelAdmin objects https://docs.djangoproject.com/en/1.8/ref/contrib/admin/#inlinemodeladmin-objects

In list view you can define your custom column Can "list_display" in a Django ModelAdmin display attributes of ForeignKey fields?

Community
  • 1
  • 1
quick
  • 1,104
  • 10
  • 19