So, let's say I have such models:
class Foo(Model): name = CharField(max_length=200) def latest_comment(self): try: object = self.comment_set.latest() if object: return object.when_posted.date() except: return "" class Comment(Model): when_posted = DateTimeField() text = TextField()
Then this is modelAdmin:
class FooAdmin(ModelAdmin): list_display = ['name', 'latest_comment'] ordering = ['latest_comment'] admin.site.register(Foo, FooAdmin)
It throws an error when I go to the admin site saying that "last_comment" was not found in app.Foo. Having this in list_display works fine. So my question is: is there a way to arrange models in list_display using model methods? And if so, how?
source share