I'm writing a management command which will filter a product's original price with suggested prices.
I have a product model which looks like :
class Suggestion(models.Model):
....
price = models.IntegerField()
class Product(models.Model):
price = models.IntegerField()
suggestions = models.ManyToManyField(Suggestion)
I want to filter all products whose price is equal to minumum suggestion. Something should like :
Product.objects.filter(price = minumum(suggestions))
AND
I want to filter products where the suggestions contains the Product's original price. Something should like :
Product.objects.filter(price__in = self.suggestions)
The problem is I can't use a for-loop to look each Product's minumum suggestion and as you guess I can't use object's self either, so how can I compare two fields of a model in a query ?