So I am simply trying to add LectureCategory in my Lecture model, I want the user to be only able to select between Classes or Seminars. If I put choices in both models, I can see them on django admin, but I get the error:
Cannot assign "'0'": "Lecture.lecture_category" must be a "LectureCategory" instance.
If I dont put choices in second model, then in admin panel will show 0 or 1, instead of my values. Any suggestion ?
class LectureCategory(models.Model):
lecture_category = models.IntegerField(choices=((0, "Classes "),
(1, "Seminars"),
))
def __str__(self):
return str(self.lecture_category)
class Lecture(models.Model):
course = models.ForeignKey('Course', on_delete=models.CASCADE, default='', related_name='lectures', null=True, )
lecture_category = models.ForeignKey('LectureCategory', on_delete=models.CASCADE,
default='', related_name='categories',
choices=((0, "Classes "),
(1, "Seminars"),
)
)
LectureCategoryshows up in the admin panel as 0 or 1 because that's how you definedLectureCategoryinstances to be printed (seeLectureCategory.__str__)