Reputation: 311
I am new at django panel, I want to show some particular fields in the index method but I see "NameClass Object" intead. I tried using fields and list_display but it didn't work.
from django.contrib import admin
from base_proyecto.models import *
class AutorAdmin(admin.ModelAdmin):
fields = ('name', 'dob', 'hp')
list_display = ('name', 'dob', 'hp')
admin.site.register(Autor)
I want to see multiple columns, one per attribute. It should look like this
Upvotes: 0
Views: 50
Reputation: 1395
Write the unicode() method in Author
model(or str() if you're using Python3),
class Author(models.Model):
# Here fields stuff
def __unicode__(self):
return self.nomber
class AutorAdmin(admin.ModelAdmin):
model = Author
fields = ('name', 'dob', 'hp')
list_display = ['name','dob', 'hp']
edit : - if you want to return multiple values then try this
def __unicode__(self):
return '%s %s %s' % (self.name, self.dob, self.hp)
Upvotes: 0
Reputation: 12086
Inside your Auto
model you must define a __str__
(for python 3) or __unicode__
(for python 2) method. Like this:
class Autor(models.Model):
name = models.CharField(max_length=50)
# other fields here
def __str__(self): # python 3
return self.name
def __unicode__(self): # python 2
return self.name
Upvotes: 1
Reputation: 2014
Define a __unicode__()
method if you're on python 2 or __str__()
if you're on python 3, for your model.
Upvotes: 0