I have tried to override the save() function on a model that is abstract, and am getting an error
JavaScript
x
2
1
Manager isn't accessible via Entry instances
2
So if possible, how do you override the save function on an abstract model. The model that extends from this is Entry
Here is my model Code:
JavaScript
1
11
11
1
class EntryBlog(EntryAbstractClass):
2
groups = models.ManyToManyField(group, null=True, blank=True)
3
4
def save(self, *args, **kwargs):
5
if self.featured:
6
self.__class__().objects.all().update(featured = False)
7
super(EntryBlog, self).save(*args, **kwargs)
8
9
class Meta:
10
abstract = True
11
(For those who are familiar, I am extending the Entry
model on the zinnia-blog, but dont think that is relevant)
Advertisement
Answer
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.