This code displays objects like this: Home Object(1) ,Home Object(2) but I want to display all the model fields in my django admin page.How can I do this?
I am very beginner in django and this is my first project.
models.py
class Home(models.Model):
image=models.ImageField(upload_to='home')
paragraph=models.TextField()
created=models.DateTimeField(auto_now_add=True)
admin.py
admin.site.register(Home)
If you want to change the display from Home Object(1) to something else, you can do this by defining a method in your model like this:
class Home(models.Model):
image=models.ImageField(upload_to='home')
paragraph=models.TextField()
created=models.DateTimeField(auto_now_add=True)
def __str__(self):
return "{}:{}..".format(self.id, self.paragraph[:10])
This will return object id with the first 10 characters in your paragraph on admin panel:
e.g:
1:Example par...
Once you click on that object, you will get object details.
If you want on panel, you can try like this in admin.py
from django.contrib import admin
class HomeAdmin(admin.ModelAdmin):
list_display = ('image', 'paragraph','created',)
admin.site.register(Home,HomeAdmin)
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With