Answer the question
In order to leave comments, you need to log in
How to add a custom field to the Django admin?
Good afternoon. Let's say there are two models:
Comment
сlass Comment(models.Model):
content_type = models.ForeignKey(ContentType, null=True)
object_id = models.PositiveIntegerField(null=True)
content_object = GenericForeignKey('content_type', 'object_id')
class News(models.Model):
title = models.CharField(max_length=250)
comments = GenericRelation(Comment, related_query_name='news')
class CommentAdmin(admin.ModelAdmin)?
Answer the question
In order to leave comments, you need to log in
class FooTheModel(Model):
title = models.CharField(max_length=250)
# blah
def __str__(self):
return "{} blah-blah".format(self.title)
ModelAdmin.list_display
class CommentAdmin(admin.ModelAdmin):
list_display = ('news__title')
class CommentAdmin(admin.ModelAdmin):
list_display = ('news_title_fnc')
def news_title_fnc(self, obj):
return obj.news.title
Didn't find what you were looking for?
Ask your questionAsk a Question
731 491 924 answers to any question