Answer the question
In order to leave comments, you need to log in
Q() object request not being executed?
There is the following model, which should describe the various characteristics of the product:
class CharacteristicType(models.Model):
name = models.CharField(_(u'Name'), max_length=255)
slug = models.SlugField(_(u'Slug'), max_length=150, unique=True,
help_text=_(u'Slug for product url created from name.'))
class Characteristic(models.Model):
characteristic_type = models.ForeignKey(CharacteristicType)
value = models.CharField(_(u'Value'), max_length=255)
product = models.ForeignKey(Product, verbose_name=_(u'Product'),
help_text=_(u'Referenced product'))
Product.objects.filter(Q(characteristic__characteristic_type__slug='brands') & Q(characteristic__characteristic_type__slug = 'ingridient'))
Answer the question
In order to leave comments, you need to log in
Oh, this is just a great request, for which there is a solution, but it is not the most obvious one:
https://docs.djangoproject.com/en/1.8/topics/db/qu... (highly recommend reading carefully)
I really had another situation, I calmly used filter sequences, and it led to incomprehensible selections.
in your case it should be like this:
and in the case of "feedback" or many-to-many relationships, these two separate filters are not the same as writing everything in one filter!
Didn't find what you were looking for?
Ask your questionAsk a Question
731 491 924 answers to any question