Код: Выделить всё
class Product(models.Model):
sku = models.CharField(unique=True) # Something like RXT00887
class Bill(models.Model):
customer = models.ForeignKey(Customer)
products = models.ManyToManyField(Product)
date = models.DateTimeField()
Я работаю над функцией, которая требует от меня поиска продуктов, купленных данным клиентом. Я добиваюсь этого с помощью:
Код: Выделить всё
bills = Bill.objects.filter(customer=customer)
results = Product.objects.filter(bill__in=bills, sku__icontains=search_str)
Подробнее здесь: https://stackoverflow.com/questions/792 ... django-orm
Мобильная версия