I am using Django 1.7. I have a custom default manager that filters the “active” boolean field. According to the documents, the default manager should be a manager for working with related fields (i.e. access to User.story_set shows only active Story objects). I support a standard manager for access to administrators and the shell, but I can’t save changes to objects, I reflect, because the save () methods at some point go through the default manager.
class Story(models.Model):
active = models.BooleanField(default=True)
....
objects = ActiveStoryManager()
full_set = models.Manager()
class ActiveStoryManager(models.Manager):
def get_query_set(self):
return super(ActiveStoryManager, self).get_query_set().filter(active=True)
use_for_related_fields = True
This works well for all users working with the public. However, in admin and shell I can not affect inactive objects, including their active inclusion.
story = Story.full_set.get(id=#) active=False, active=True ,
django.db.utils.IntegrityError: duplicate key value violates unique constraint "stories_story_pkey"
DETAIL: Key (id)=(#) already exists.
save.(force_update=True) django.db.utils.DatabaseError: Forced update did not affect any rows.
, save() , , , - .
API Queryset, . Story.full_set.filter(id=#).update(active=True), , - admin.
?