Django Admin, Update, Delete and Add Member| 8th Video

Published: 02 June 2023
on channel: Abdul Wahab DAAD
116
4

Django Admin is a really great tool in Django, it is actually a CRUD* user interface of all your models.
To be able to log into the admin application, we need to create a user.
To include the Member model in the admin interface, we have to tell Django that this model should be visible in the admin interface.
In the list in the screenshot above, we see "Member object (1)", "Member object (2)" etc. which might not be the data you wanted to be displayed in the list.

It would be better to display "firstname" and "lastname" instead.

This can easily be done by changing some settings in the models.py and/or the admin.py files.
When you display a Model as a list, Django displays each record as the string representation of the record object, which in our case is "Member object (1)", "Member object(2)" etc.:
To change this to a more reader-friendly format, we have two choices:

Change the string representation function, __str__() of the Member Model
Set the list_details property of the Member Model.
We can control the fields to display by specifying them in in a list_display property in the admin.py file.

First create a MemberAdmin() class and specify the list_display tuple, like this:Now we are able to create, update, and delete members in our database, and we start by giving them all a date for when they became members.


Watch video Django Admin, Update, Delete and Add Member| 8th Video online without registration, duration hours minute second in high quality. This video was added by user Abdul Wahab DAAD 02 June 2023, don't forget to share it with your friends and acquaintances, it has been viewed on our site 116 once and liked it 4 people.