Answer the question
In order to leave comments, you need to log in
How to display many-to-many relationships in both tables in Django admin?
Let's say we have a school, and one lesson can be taught by several teachers, and teachers are generalists and can lead various lessons.
models.py:
# Таблица для хранения УЧИТЕЛЕЙ
class Coach (models.Model):
CoachHeader = models.CharField(
max_length = 256,
help_text = u"Имя Фамилия"
)
CoachPhoto = models.ImageField(
max_length = 255,
upload_to = "coach_img/",
default = "",
null = True,
blank = True,
help_text = u"Путь до картинки",
)
def __unicode__(self):
return u"%03d: %s" % (self.id, self.CoachHeader)
# Таблица для хранения ЗАНЯТИЙ
class Lesson (models.Model):
LessonHeader = models.CharField(
max_length = 256,
help_text = u"Название занятия"
)
LessonAd = models.CharField(
max_length = 1024,
unique = False,
null = True,
blank = True,
help_text = u"Анонс (краткое описание)"
)
Lesson2Coach = models.ManyToManyField(
"Coach",
null = True,
blank = True,
help_text = u"Учителя ведущие занятие"
)
def __unicode__(self):
return u"%03d: %s" % (self.id, self.LessonHeader)
Answer the question
In order to leave comments, you need to log in
Didn't find what you were looking for?
Ask your questionAsk a Question
731 491 924 answers to any question