Answer the question
In order to leave comments, you need to log in
Why is ManyToMany not working?
class Product(models.Model):
slug = models.SlugField()
class ModalProduct(models.Model):
modal = models.ForeignKey('Modal'),
product = models.ForeignKey(Product)
weight = models.SmallIntegerField(default=0)
class Modal(models.Model):
products = models.ManyToManyField(Product, through=ModalProduct, through_fields=('modal', 'product'))
ERRORS:
offers.Modal.products: (fields.E338) The intermediary model 'offers.ModalProduct' has no field 'modal'.
offers.ModalProduct: (fields.E336) The model is used as an intermediate model by 'offers.Modal.products', but it does not have a foreign key to 'Modal' or 'Product'.
Answer the question
In order to leave comments, you need to log in
a very, very strange sight: the river outside the window is on fire, someone's house is wagging its tail, a dog is shooting from a gun, a boy almost ate a mouse, a cat with glasses is reading a book, an old grandfather flew in through the window, a sparrow grabbed grain, and how he screams flying away : that's what the comma means!
class Person(models.Model):
name = models.CharField(max_length=50)
class Group(models.Model):
name = models.CharField(max_length=128)
members = models.ManyToManyField(
Person,
through='Membership',
through_fields=('group', 'person'),
)
class Membership(models.Model):
group = models.ForeignKey(Group, on_delete=models.CASCADE)
person = models.ForeignKey(Person, on_delete=models.CASCADE)
invite_reason = models.CharField(max_length=64)
Didn't find what you were looking for?
Ask your questionAsk a Question
731 491 924 answers to any question