Question

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

Était-ce utile?

La solution

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.

Licencié sous: CC-BY-SA avec attribution
Non affilié à StackOverflow
scroll top