I have a model which uses an InlinePanel
to reference another model (ClubTimetable
) which itself contains an M2M relationship to DayOfTheWeek
. It seems as though I am unable to save the record because ClubTimetable
is not yet saved and cannot create the M2M relationship to DayOfTheWeek
, causing the following error:
"<ClubTimetables: Club Timetable (str) 18:00:00>" needs to have a value for field "id" before this many-to-many relationship can be used.
What can I do to solve this issue?
My models look like this
# ClubManager
@register_snippet
class ClubManager(ClusterableModel):
name = models.CharField('Club name',
max_length=255,
help_text='The name of the club.')
panels = [
FieldPanel('name'),
InlinePanel('club_timetable', heading='Timetable Information')
]
# ClubTimetables
class ClubTimetables(Orderable, AddressBase):
attached_to = ParentalKey(
'club.ClubManager', related_name='club_timetable')
weekday = models.ManyToManyField(DaysOfTheWeek)
start_time = models.TimeField()
end_time = models.TimeField()
panels = [ ... ] + AddressBase.panels
# DaysOfTheWeek
class DaysOfTheWeek(models.Model):
weekday = models.CharField(max_length=9)
def __str__(self):
return self.weekday
Visually, it looks like this
(Initial)
(Adding timetable)
与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…