Answer the question
In order to leave comments, you need to log in
How to get collections that have products with a specific room value?
There are 3 models:
ProductCollections = collections that include products
class ProductCollections(models.Model):
title = models.CharField(max_length=255, verbose_name='Название')
slug = models.SlugField(unique=True)
img = models.ImageField(verbose_name='Фото')
price = models.PositiveIntegerField(default=0, verbose_name='Цена от')
def __str__(self):
return self.title
class Meta:
verbose_name = 'Коллекция'
verbose_name_plural = 'Коллекции'
class Product(models.Model):
# collection = models.ForeignKey("Collections", verbose_name="Коллекция", on_delete=models.CASCADE)
title = models.CharField(max_length=255, verbose_name="Название")
slug = models.SlugField(unique=True)
price = models.PositiveIntegerField( default=0, verbose_name="Цена")
img = models.ImageField(verbose_name='Фото')
# Many to many
collections = models.ManyToManyField('ProductCollections', verbose_name='Колекция')
premises = models.ManyToManyField('Premises', verbose_name='Помещение')
def __str__(self):
return self.title
class Meta:
verbose_name = 'Товар'
verbose_name_plural = 'Товары'
class Premises(models.Model):
title = models.CharField(max_length=255, verbose_name='Название')
def __str__(self):
return self.title
class Meta:
verbose_name = '--- Помещение'
verbose_name_plural = '--- Помещения'
Answer the question
In order to leave comments, you need to log in
Didn't find what you were looking for?
Ask your questionAsk a Question
731 491 924 answers to any question