Y
Y
Yarovoy Ivan2015-01-22 15:19:50
Django
Yarovoy Ivan, 2015-01-22 15:19:50

Django - how to override the save method so that the product categories change?

Hello everyone
, there is a
class CategoryConverter(models.Model):
product = models.ManyToManyField(Product, blank=True, null=True)
category = models.ForeignKey(Category, blank=True, null=True)
def save(self, *args , **kwargs):
self.product.all().update(category=self.category)
return super(CategoryConverter, self).save(*args, **kwargs)
takes categories but products have no
model :
class Product( models.Model):
category = TreeManyToManyField(Category, verbose_name=u'Category')
...
class Category(MPTTModel):
title = models.CharField(u'Title', max_length=60)
...

Answer the question

In order to leave comments, you need to log in

1 answer(s)
L
leclecovich, 2015-01-22
@leclecovich

Try linking the Product and Category models through the third model using through ( https://docs.djangoproject.com/en/1.7/ref/models/f... In the case of django.models, this would be an unambiguous must have, however mptt can complicate the already difficult life of a developer.

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question