Skip to content
Advertisement

django charfield not showing in admin panel

i create a model in django and register it in admin.py when i go to admin panel it shows the model but when i want to create object it doesn’t show the charfields and i can just create the oject without any details

this is my codes below

view.py

JavaScript

model.py

JavaScript

stting.py

JavaScript

admin.py

JavaScript

this screenshot is from my admin panel > add Feature (myModel) and it shows nothing.

screenshot of admin panel> add Feature

Advertisement

Answer

You are using a @dataclass way of defining your model. I’m not aware that will work … It should be:

JavaScript

Also, have you run migrations? (I suspect not or I think you’d have seen an error here). You should run python manage.py makemigrations followed by python manage.py migrate when you create or amend a model definition – this is what creates/changes it in the DB, and without that there’s not a lot to display in admin anyway …

It’s possible if you ran migrate it created an “empty” model maybe, since you were missing the = – I really don’t know exactly what this code would do without testing it.

User contributions licensed under: CC BY-SA
5 People found this is helpful
Advertisement