Issue
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 columns in Django admin, as it is in users:
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 registers on admin site as I can see it as:
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']
Answered By - Eugenij
0 comments:
Post a Comment
Note: Only a member of this blog may post a comment.