I'm reviewing tutorials and the form to customize my administrator's table does not appear. In other words, it looks like this, I mean I want the table to be more descriptive but it only puts "clients" for me, neither the ID nor the license, zip, etc. appears:
I present the code, seriously I don't see any errors but hey, I'm a novice. Thank you!!!! :) :
models
class Clientes(models.Model):
nombre =models.CharField(max_length=80)
apellido=models.CharField(max_length=80)
licencia = models.CharField(max_length=30)
direccion = models.CharField(max_length=30)
zip = models.IntegerField()
ciudad = models.CharField(max_length=45)
estado = models.CharField(max_length=45)
telefono = models.IntegerField()
fax = models.IntegerField()
descuento = models.IntegerField()
correo = models.EmailField(max_length=30)
carro = models.ForeignKey(Carro,on_delete=models.SET_NULL, null=True)
def __str__(self):
return f'{self.id}: {self.nombre} {self.apellido} {self.licencia} {self.direccion}'
admin
from django.contrib import admin
from clientes.models import Clientes, Carro, ClienteEmpresa
# Register your models here.
class ClientesAdmin(admin.ModelAdmin):
list_display= ('nombre', 'apellido', 'licencia')
admin.site.register(Clientes)
To register a model in the admin you have several alternatives:
which is equal to...
In your code you are using option 1) , that is, you are using the default interface. To correct the behavior you must pass as the second parameter a
ClientesAdmin
in the methodadmin.site.register
.Note. You can use the decorator
admin.register
to save yourselfadmin.site.register(...)
. In this case your code would look like: