开发者

Django: override the save() function of an abstract model

开发者 https://www.devze.com 2023-02-14 01:23 出处:网络
I have tried to override the save() function on a model that is abstract, and am getting an error Manager isn\'t accessible via Entry instances

I have tried to override the save() function on a model that is abstract, and am getting an error

Manager isn't accessible via Entry instances

So if possible, how do you override t开发者_如何学编程he save function on an abstract model. The model that extends from this is Entry

Here is my model Code:

class EntryBlog(EntryAbstractClass):
    groups = models.ManyToManyField(group, null=True, blank=True)    

    def save(self, *args, **kwargs):
        if self.featured:
            self.__class__().objects.all().update(featured = False)
        super(EntryBlog, self).save(*args, **kwargs)

    class Meta:
        abstract = True

(For those who are familiar, I am extending the Entry model on the zinnia-blog, but dont think that is relevant)


self.__class__().objects should be self.__class__.objects.

See the Notes on retrieving objects: http://docs.djangoproject.com/en/dev/topics/db/queries/#retrieving-objects

Managers are accessible only via model classes, rather than from model instances, to enforce a separation between "table-level" operations and "record-level" operations.

0

精彩评论

暂无评论...
验证码 换一张
取 消