第二页= ParentalKey()定义,在不同的Page模型中使用一个snippen

时间:2018-02-07 14:36:58

标签: wagtail

我定义了两个Relationship(Orderable, models.Model),以便能够在不同的Page模型中使用一个modelsnippet,如:

class GroupstageTournamentModel(models.Model):
...
class GroupstageTournamentRelationship(Orderable, models.Model):
    page = ParentalKey('TournamentPage',
        related_name='groupstage_tournament_relationship')
    match = models.ForeignKey('GroupstageTournamentModel',
        related_name='match_tournament_relationship')
    panels = [
        PageChooserPanel('match')
    ]
class MatchesScreencastRelationship(Orderable, models.Model):
    page = ParentalKey('ScreencastPage',
        related_name='groupstage_screencast_relationship')
    match = models.ForeignKey('GroupstageTournamentModel',
        default="", related_name='match_screen_relationship')
    panels = [
        PageChooserPanel('match')
    ]

class TournamentPage(Page):
    starts_at = models.DateTimeField(blank=True)
    ends_at = models.DateTimeField(blank=True)

    content_panels = Page.content_panels + [
        FieldPanel('title'),
        FieldPanel('starts_at'),
        FieldPanel('ends_at'),
        InlinePanel(
            'groupstage_tournament_relationship', label="Group game:",
            panels=None, min_num=1),
    ]

    def __str__(self):
        return self.title

class ScreencastPage(Page):

    content_panels = Page.content_panels + [
        FieldPanel('title'),
        InlinePanel(
            'groupstage_screencast_relationship', label="Playing First",
            panels=None, max_num=1),
    ]

    parent_page_types = ['home.HomePage']
    subpage_types = []

    def __str__(self):
        # return self.title
        return '{} \n Nächste: {}'.format(self.groupstage_relationship, self.final_phase_relationship)

正如您所看到的,我的想法是使用其中一个TournamentPage而另一个ScreencastPage。如果我这样做,我得到这个错误:

错误:

django.core.exceptions.FieldError: Local field 'id' in class 'GroupstageTournamentRelationship' clashes with field of the same name from base class 'GroupstageTournamentModel'.

如何解决这个问题?是否有可能以某种方式添加第二个ParentalKey与ScreencastPage的关系,并像在backerydemo中一样直接在GroupstageTournamentModel内使用?

更新

我将GroupstageTournamentModelmodel.Model更改为ClusterableModel,然后我更改了related_name,以便related_name中的related_name='groupstage_tournament_relationship'改为related_name='groupstage_screencast_relationship' GroupstageTournamentRelationshipclass GroupstageTournamentModel(ClusterableModel): number = models.PositiveSmallIntegerField( help_text="Add the unique number of this Match.") starts_at = models.DateTimeField() # Team 1 team_1 = models.ForeignKey( TeamRooster, null=True, blank=True, on_delete=models.SET_NULL, related_name="+", ) team_1_dress = ColorField(default='#ff0000', blank=True) team_1_first_halftime_score = models.PositiveSmallIntegerField(blank=True, default="") # Team 2 team_2 = models.ForeignKey( TeamRooster, null=True, blank=True, on_delete=models.SET_NULL, related_name="+", ) team_2_dress = ColorField(default='#0066ff', blank=True) team_2_first_halftime_score = models.PositiveSmallIntegerField(blank=True, default="") panels = [ FieldPanel('number', classname="6"), FieldPanel('starts_at', classname="6"), MultiFieldPanel([ FieldRowPanel([ FieldPanel('team_1', classname="6"), FieldPanel('team_1_dress', classname="6"), FieldPanel('team_1_first_halftime_score', classname="3"), ]), ], classname="full", heading="Team 1"), MultiFieldPanel([ FieldRowPanel([ FieldPanel('team_2', classname="6"), FieldPanel('team_2_dress', classname="6"), FieldPanel('team_2_first_halftime_score', classname="3"), ]), ], classname="full", heading="Team 2"), ] def __str__(self): return '{} vs {} {} - {}'.format(self.team_1, self.team_2, self.starts_at, self.number) class Meta: verbose_name = 'Gruppenphase Spiel' verbose_name_plural = 'Gruppenphase' 。我再次进行迁移并得到了同样的错误。这是我的SELECT p.team_id, p.first, pd.height FROM players p JOIN player_data pd ON pd.player_id = p.player_id WHERE (p.team_id, pd.height) IN (SELECT p.team_id, MAX(pd.height) FROM players p JOIN player_data pd ON pd.player_id = p.player_id GROUP BY p.team_id) 课程:

var gulp = require('gulp');
var concatCss = require('gulp-concat-css');

gulp.task('default', function () {
  return gulp.src('cssfolder/*.css')
    .pipe(concatCss("bundle.css"))
    .pipe(gulp.dest('out/'));
});

更新

在迁移文件中,我发现了以下内容,我不确定如果删除它会发生什么:

enter image description here

更新

为了清晰起见,我缩短了模型并添加了“TournamentPage”。

1 个答案:

答案 0 :(得分:0)

我删除了包含0001_inicial.py的迁移文件,并再次py manage.py makemigrations,这一切都有效!