| 5 | | In other words, the `get_initial_queryset` hook saves you from defining a manager but you still have to define a method. It also ties your queryset class to a single manager usage with seems wrong? What if you want to use your custom queryset class with two different filters sets |
| | 5 | In other words, the `get_initial_queryset` hook saves you from defining a manager but you still have to define a method. It also ties your queryset class to a single manager usage with seems wrong? What if you want to use your custom queryset class with two different filters sets? |
| | 6 | |
| | 7 | Some code example might help understanding better here. |
| | 8 | |
| | 9 | Today the ''problem'' is |
| | 10 | |
| | 11 | {{{#!python |
| | 12 | class FooQueryset(models.QuerySet): |
| | 13 | def is_bar(self): |
| | 14 | return self.filter(bar=True) |
| | 15 | |
| | 16 | class FooBazManager(FooQueryset.as_manager()): |
| | 17 | def get_queryset(self): |
| | 18 | return super().get_queryset().filter(baz=True) |
| | 19 | |
| | 20 | class FooBatQueryset(FooQueryset.as_manager()): |
| | 21 | ddef get_queryset(self): |
| | 22 | return super().get_queryset().filter(baz=True) |
| | 23 | |
| | 24 | class Foo(models.Model): |
| | 25 | bar = models.BooleanField() |
| | 26 | baz = models.BooleanField() |
| | 27 | bat = models.BooleanField() |
| | 28 | |
| | 29 | objects = FooQueryset.as_manager() |
| | 30 | baz_objects = FooBazQueryset.as_manager() |
| | 31 | bat_objects = FooBatQueryset.as_manager() |
| | 32 | }}} |
| | 33 | |
| | 34 | What `get_initial_queryset` would allow |