You can do this by writing a custom Manager - just override the get_queryset method and set objects to the manager instance. For example:
class MyModelManager(models.Manager): def get_queryset(self): return super(MyModelManager, self).get_queryset().filter(published=True) class MyModel(models.Model):
See docs for more details. It makes sense if this is your normal default case. To get unpublished, create another manager that you can access, for example, MyModel.unpublished_objects . Again, documents have examples of this type of thing.
ars
source share