> To accomplish this we are going to add a 'deleted_flag' to > each table, and set it to 0 if it is not deleted, and 1 if it > is deleted. > > Rather than going to every function I am displaying items ( > 99% of the time I'm using .filter then some filter ), is there > a way to tell it in the model to always append delete_flag=0 > to any of the .filter parameters I am passing in, so that only > non logically deleted items are returned? I just thought I'd > check before trolling through thousands of lines of code for > all of my .filter statements.
well, depending on the number of models you have (presuming you have a manageable number) you can simply add a custom manager to each model...something like class NonDeleted(models.Manager): def get_query_set(self): return super(NonDeleted, self).get_query_set().filter( delete_flag = 0) and then attach that as your "objects" property (which is normally just a models.Manager() instance): class Foo(Model): field_baz = ... objects = NonDeleted() class Bar(Model): otherfield = ... objects = NonDeleted() You can read all about custom managers at http://www.djangoproject.com/documentation/model-api/#managers and in particular at http://www.djangoproject.com/documentation/model-api/#modifying-initial-manager-querysets You can even include the deleted optionally via a secondary manager: objects = NonDeleted() all_objects_including_deleted = models.Manager() With the above in place, you should only need to touch your models, not any view code. -tim --~--~---------~--~----~------------~-------~--~----~ You received this message because you are subscribed to the Google Groups "Django users" group. To post to this group, send email to django-users@googlegroups.com To unsubscribe from this group, send email to [EMAIL PROTECTED] For more options, visit this group at http://groups.google.com/group/django-users?hl=en -~----------~----~----~----~------~----~------~--~---