Welcome to OStack Knowledge Sharing Community for programmer and developer-Open, Learning and Share
Welcome To Ask or Share your Answers For Others

Categories

0 votes
3.9k views
in Technique[技术] by (71.8m points)

django - Wagtail - How to save a record which uses InlinePanel containing M2M

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) Initial view

(Adding timetable) After adding timetable


与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
Welcome To Ask or Share your Answers For Others

1 Answer

0 votes
by (71.8m points)
等待大神答复

与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
Welcome to OStack Knowledge Sharing Community for programmer and developer-Open, Learning and Share
Click Here to Ask a Question

...