﻿id	summary	reporter	owner	description	type	status	component	version	severity	resolution	keywords	cc	stage	has_patch	needs_docs	needs_tests	needs_better_patch	easy	ui_ux
14295	Saving an object with a custom manager results in IntegrityError	loekje	nobody	"I have defined customer manager that filters out certain object (e.g. those objects marked as inactive). 
The customer manager is the first manager defined in the model, consequently it is used as the default manager for this model.
Additionally, I have defined another manager for the model that does no filtering (i.e. the standard manager).

When properties of an inactive object are updated and the inactive object is saved, an IntegrityError is raised. This is because the default manager cannot find the object and attempts to insert the object again instead of updating it. 
{{{
class MyModelManager(models.Manager):
   def get_query_set(self):
      return super(MyModelManager, self).get_query_set().filter(is_active=True)

class MyModel: models.Model
   name=CharField
   ... some additional properties ...
   is_active=BooleanField

   objects=MyModelManager()
   objects_all=models.Manager()

m=MyModel()
m.name='John'
m.is_active=False
m.save()

m.name='John Doe'
m.save()
--> IntegrityError!!!
}}}
I would like that the default manager can be set such that inactive objects are not shown (i.e. also not when using mymodel_set on related objects) such that by default the inactive objects are not taken into account. However, to avoid the IntegrityError when saving an object I would like to be capable of overruling a manager that has to be used by save (and most likely also by delete), in the model and/or as in argument in the save call.
"		closed	Uncategorized	1.0		worksforme			Unreviewed	0	0	0	0	0	0
