M
M
mr_drinkens892014-08-04 20:11:37
Django
mr_drinkens89, 2014-08-04 20:11:37

How to display product features in django admin?

There is an electronics store on django. There is a model - Product, which stores information about the product. Each product has its own technical characteristics (processor - clock frequency, monitor - diagonal, hard disk - volume, etc.). At the moment, you have to fill in the fields "by hand" for each product: select a parameter (for example, a monitor), write its description on the right. We add one more parameter - and again the description. And so for each product.
How can I make it so that, for example, by going to the HP-530 product card, you can select the "laptops" group, save it - and a certain field template will be displayed (on the left is the parameter, on the right is its description)?
Thank you

Answer the question

In order to leave comments, you need to log in

3 answer(s)
D
denizen, 2014-08-04
@denizen

Take a look at django-eav - it might work.

M
mr_drinkens89, 2014-08-05
@mr_drinkens89

class TechInfo(models.Model):
    title = models.CharField(_(u'заголовок'), max_length=255)

    def __unicode__(self):
        return  self.title

    class Meta:
        ordering = ('title',)

class ProductTechInfo(models.Model):
    """техническая информация для продуктов
    """
    product = models.ForeignKey(Product, verbose_name=_(u"товар"), related_name="techinfo")
    name = models.ForeignKey(TechInfo, verbose_name=_(u"имя"), related_name="name")
    value = models.TextField(_(u'значение'), blank=True)
    separator = models.BooleanField(_(u'заголовок?'), default=False)
    position = models.SmallIntegerField(_(u'позиция'), default=999)

    def __unicode__(self):
        return  u"%s" % (self.name)

    class Meta:
        ordering = ('position',)
        verbose_name = _(u'техническая информация')
        verbose_name_plural = _(u'техническая информация')

in the ProductTechInfo model there is a link to Product through product = models.ForeignKey(Product...).
In the admin panel, ProductTechInfo is already displayed as Inline: each time we add a new characteristic, select its property from the list, and manually write the attribute.
I read another solution:
we add a field to the product as a regular string. And in it we save as a list all the characteristics. In the template - parse and output. And the whole thing is saved through the form in the admin panel. Of course, this is the most primitive option, and you don’t want to use it at all. Plus, there will be difficulties in editing and adding new fields.

M
Maxim Vasiliev, 2014-08-05
@qmax

Maybe you need
https://docs.djangoproject.com/en/1.6/ref/contrib/...

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question