Category Names not shown. Object (1)

Asked

Viewed 56 times

1

Can someone help me fix why the category names are not being displayed in my admin console?

from django.db import models
from django.conf import settings

class Cad_pref(models.Model):
    nomepref = models.CharField("Nome Prefeitura:", max_length=200)
    endpref = models.CharField("Endereço Prefeitura:", max_length=200)
    numpref = models.CharField("Número Prefeitura:", max_length=10)
    telpref = models.CharField("Telefone Prefeitura:", max_length=15)
    cnpjpref = models.CharField("CNPJ:", max_length=15)

inserir a descrição da imagem aqui

  • Have you tried implementing the method __str__ with the value you want?

  • I’m sorry to ignore, I searched on Django’s website and did not see about. This panel is "default" of it?

2 answers

0

Try it buddy:

from django.db import models
from django.conf import settings

class Cad_pref(models.Model):
nomepref = models.CharField("Nome Prefeitura:", max_length=200)
endpref = models.CharField("Endereço Prefeitura:", max_length=200)
numpref = models.CharField("Número Prefeitura:", max_length=10)
telpref = models.CharField("Telefone Prefeitura:", max_length=15)
cnpjpref = models.CharField("CNPJ:", max_length=15)

    def __str__(self):
        return self.nomepref

0

Fabio, you can choose the name that will appear for each Django template created by you. just implement the method:

def __str__(self): return self.name

In your case I’d be:

from django.db import models
from django.conf import settings

class Cad_pref(models.Model):
    nomepref = models.CharField("Nome Prefeitura:", max_length=200)
    endpref = models.CharField("Endereço Prefeitura:", max_length=200)
    numpref = models.CharField("Número Prefeitura:", max_length=10)
    telpref = models.CharField("Telefone Prefeitura:", max_length=15)
    cnpjpref = models.CharField("CNPJ:", max_length=15)

 def __str__(self):
        return self.nomepref #pondo aqui o nome que você quer que apareça em seu admin

You can read more about here

Browser other questions tagged

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