4👍
✅
You can add multiple managers to your model. For example:
class MyModelManager(models.Manager):
def get_queryset(self):
return super(MyModelManager, self).get_queryset().exclude(is_visible=False)
class MyModel(models.Model):
# …
objects = MyModelManager()
all_objects = models.Manager()
If you then need all the objects, you can thus access these with MyModel.all_objects.all()
.
0👍
You can use another custom manager which does not override get_queryset() method and it would be better if you use different name then common objects name that you have to define custom manager only once.
- [Django]-Django raw sql with datetime
- [Django]-How to create 'terms & conditions check box' in django?
- [Django]-Using classes for Django views, is it Pythonic?
Source:stackexchange.com