S
S
s7fkcu2019-05-30 12:18:14
Django
s7fkcu, 2019-05-30 12:18:14

Django coupon system?

Good afternoon everyone. Implemented a coupon system, but with a one-to-many relationship to product categories (i.e. for all products in a given category). How to implement correctly with m2m connection so that 1 coupon has many categories?
I would be grateful for examples and hints. Thanks

Answer the question

In order to leave comments, you need to log in

1 answer(s)
F
FulTupFul, 2019-05-30
@FulTupFul

class Category(models.Model):
    pass

class Coupon(models.Model):
    categories = models.ManyToManyField('Category')

coupon = Coupon.objects.create()
categories = Category.objects.filter(id__in=[1, 2])
coupon.categories.add(categories)

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question