문제

Is there any default action to allow a contenttype only once per page, other then overriding the admin form? The documentation is unclear about this

도움이 되었습니까?

해결책

I don't think there's an out-of-the-box implementation, you could suggest one at Github. Since a FeinCMS content type is an abstract Django Model class you could use its clean method, e.g.

class FooContent(models.Model):
    content = models.Bar('...')

    class Meta:
        abstract = True

    def clean(self):
        if self.parent.foocontent_set.count() >= 1:
            raise ValidationError('FooContent is only allowed once per Page.')

    def render(self, **kwargs):
        return render_to_string('content/foo.html', {
            'content': self.content
        })

This will raise a non field error on the admin form.

라이센스 : CC-BY-SA ~와 함께 속성
제휴하지 않습니다 StackOverflow
scroll top