Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

list_display doesn't work

Tags:

python

django

There is a class named Employees in models.py

class Employees(models.Model):
    employee_id = models.CharField(verbose_name = _("Employee ID"), max_length=20, primary_key=True)
    employee_name = models.CharField(verbose_name = _("Employee Name"), max_length=20)
    department = models.CharField(verbose_name = _("Department"), max_length=100)
    post = models.CharField(verbose_name = _("Post"), max_length=100)

Then I wrote some code in admin.py

class EmployeesAdmin(admin.ModelAdmin):
    list_display = ('employee_id', 'employee_name', 'department', 'post')

According to the tutorial, there should be four fields in the Employee branch. But in my situation, there is only one field named Employees, just like I didn't add EmployeesAdmin class in admin.py. What's wrong with it? Did I miss something?


admin.py:

from django.contrib import admin
from .models import Employees, Purchase, ProductsOut

# Register your models here.
admin.site.register(Employees)
admin.site.register(Purchase)
admin.site.register(ProductsOut)
like image 292
Searene Avatar asked Dec 05 '22 03:12

Searene


1 Answers

Register your admin in admin.site like:-

admin.site.register(ModelName, AdminName)
like image 78
Vaibhav Kumar Avatar answered Dec 18 '22 06:12

Vaibhav Kumar