Follow

Keep Up to Date with the Most Important News

By pressing the Subscribe button, you confirm that you have read and are agreeing to our Privacy Policy and Terms of Use
Contact

Django Models return fileds as columns for django admin

I looked a lot but I couldn’t find a way to return my model to django admin with the columns not only the model name:

What I wish to accomplish from my model is to have the fields represent as columns in django admin, such as it is in users:

enter image description here

MEDevel.com: Open-source for Healthcare and Education

Collecting and validating open-source software for healthcare, education, enterprise, development, medical imaging, medical records, and digital pathology.

Visit Medevel

I have a model called Products:

from django.db import models

# Create your models here.
class Product(models.Model):
    title = models.CharField(max_length=30, null=False, blank=False)
    price = models.FloatField(null=False, blank=False)
    description = models.CharField(max_length=250, null=False, blank=False)
    longDescription = models.TextField(max_length=900, null=True, blank=True)

    def __str__(self):
        return self.title

It’s register on admin site so I can see it as:

enter image description here

I’m looking for a way to have my products listed as users, with the id, price, description as columns… Is it possible?

Thanks in advance!

>Solution :

You should fill ModelAdmin.list_display for your ProductAdmin like this

class ProductAdmin(ModelAdmin):
    list_display = ['id', 'price', 'description']

Add a comment

Leave a Reply

Keep Up to Date with the Most Important News

By pressing the Subscribe button, you confirm that you have read and are agreeing to our Privacy Policy and Terms of Use

Discover more from Dev solutions

Subscribe now to keep reading and get access to the full archive.

Continue reading