Return student name in query along with matricula - python and Django admin

Asked

Viewed 19 times

-1

Base Class:

class Base(models.Model):
IncPor = models.IntegerField('Incluido Por', null=True, blank=True)
AltPor = models.IntegerField('Alterado Por', null=True, blank=True)
IncEm = models.DateTimeField('Incluido Em', auto_now_add=True)
AltEm = models.DateTimeField('Alterado Em', auto_now=True)

class Meta:
    abstract = True

Classe Pessoa:

class Pessoa(Base):    
nome = models.CharField('Nome', max_length=150)
data_nascimento = models.DateField('Data de nascimento', null=True)
pessoa_status = models.BooleanField('Pessoa ativa?', default=True)

def __str__(self):
    return self.nome

Pupil Class:

class Aluno(models.Model):
pessoa = models.ForeignKey("Pessoa", on_delete=models.CASCADE, null=True)
matricula = models.IntegerField('Matricula', unique=True)
aluno_status = models.BooleanField('Aluno ativo? ', default=True)

def __str__(self):
    return str(self.matricula)

I would like to return in the query in the file admin.py to registration and name of the student. The relationship is 1 - n. A person can have multiple license plates, and a license plate can be a person.

@admin.register(Aluno)
class AdminAluno(admin.ModelAdmin):
list_display = ('matricula', )

Error:

ERRORS: <class 'core.admin.Adminaluno'>: (admin.E108) The value of list_display[1]' refers to 'name', which is not a callable, an attribute of 'Adminaluno', or an attribute or method on 'core. Student'.

System check identified 1 Issue (0 silenced).

No answers

Browser other questions tagged

You are not signed in. Login or sign up in order to post.