Answer the question
In order to leave comments, you need to log in
How to make two m2m fields with a link to one table?
Model example
class Naznach(models.Model):
GROUP = (
('Продукты', 'Продукты'),
('Общепит', 'Общепит'),
('Другое', 'Другое')
)
group = models.CharField("Группа", max_length=30, choices=GROUP, default="F")
options = models.CharField("Назначения", max_length=100)
def __str__(self):
return self.options
class Client(models.Model):
naznach_one = models.ManyToManyField(Naznach, verbose_name="Назначение №1")
naznach_two = models.ManyToManyField(Naznach, blank=True, verbose_name="Назначение №2")
Answer the question
In order to leave comments, you need to log in
related_name
you need to add or remove a backlink in each field related_name='+'
. It also is written in an error. I advise you to use Google more often.
class Client(models.Model):
naznach_one = models.ManyToManyField(Naznach, verbose_name="Назначение №1", related_name='naznach_one_set' )
naznach_two = models.ManyToManyField(Naznach, blank=True, verbose_name="Назначение №2" related_name='naznach_two_set')
Didn't find what you were looking for?
Ask your questionAsk a Question
731 491 924 answers to any question