Try This:
class Author(models.Model):
author_name=models.CharField(max_length=300)
def __str__(self):
return self.author_name
Follow what @dirkgroten said "Make it a habit to always override str for all your models"
Also You can use list_display
method in your admin.py
to achieve similar result. Create a admin class and use list_display
to render fields of model in tabular format
Admin.py
from app.models import Artist #<-----Import you artist model
@admin.register(Artist) #<----- admin class should be just below this line
class ArtistAdmin(admin.ModelAdmin):
list_display = ["id", "author_name"]
Or you can also do this:
from app.models import Artist #<-----Import you artist model
class ArtistAdmin(admin.ModelAdmin):
list_display = ["id", "author_name"]
admin.site.register(Artist, ArtistAdmin) #<----register your class also