These are chat archives for django/django

May 2017
Anish Shrestha
May 27 2017 02:09
@Apophus look through the stack trace. You are probably including
fields = ['x', ...] in or or some related files.
Tushant Khatiwada
May 27 2017 06:49
I have an entity of Products, category and sub-category. A category can have many products and also a category can have many sub-categories. For example a product called Iphone-4 can fall on smart phone subcategories of Electronics & Gadgets Category. Similiary samsung product can fall on same smart-phone sub-categories of Electronics&Gadgets Category. How could i show this relation effectively?
The following way in my admin, the categories and sub-categories are shown so vaguely. Category Electronics & Gadgets is shown multiple times. It is shown as per the number of sub-category that falls under this category. Is this expected behavior or has to handle this other effective way?
class Category(models.Model):
    name = models.CharField(max_length=80, null=True)
    parent = models.ForeignKey('self', blank=True, null=True, related_name="children")

    class Meta:
        unique_together = ('parent',)
        verbose_name = 'Category'
        verbose_name_plural = 'Categories'

class Product(models.Model):
    token = models.CharField(default=token_generator, max_length=20, unique=True, editable=False)
    category = models.ForeignKey(Category)
    company = models.ForeignKey(Company, related_name="company_product")
    name = models.CharField(max_length=200, null=True)
    model = models.CharField(max_length=100, blank=True, null=True)
    specification = models.TextField(null=True, blank=True)
    price = models.PositiveIntegerField(default=0)

class ProductAdmin(admin.ModelAdmin):
    list_select_related = ('category', 'company',)
    class Meta:
        model = Product

class CategoryAdmin(admin.ModelAdmin):
    list_select_related = ('parent',)
    list_display = ('name', 'parent', )
    class Meta:
        model = Category
Bende Falanga Joshua
May 27 2017 11:19