jazzband / jazzband/django-model-utils

StatusModel status managers don't have custom methods of a default manager

Open
#486 0 comments 0 reactions 0 assignees View on GitHub
Dominant language
Python
Stars
2.8k
Forks
374
PR merge metrics
No merged PRs in 30d

Description

## Problem

Sometimes you might want to add a custom manager with custom queryset methods to a model that inherits `StatusModel`. (for example, via `.as_manager()` method of a queryset class):

```python
class CustomQuerySet(models.QuerySet):

def custom_qs_method(self):
return self.filter(feedback='')

class Consultation(StatusModel):
STATUS = Choices('PENDING', 'FINISHED')
feedback = models.TextField(default='')

objects = CustomQuerySet.as_manager()

```
Later, you might need to apply the methods to a queryset that filtered by a status value. I guess, it would be nice to use a manager for a specific status, provided by `StatusModel` (in this way we don't need to add `.filter(status=value)` each time or to define extra methods in custom managers). So, It would be nice to be able to do something like that:

```python
Consultation.FINISHED.custom_qs_method()
```

But currently it's not possible, because status manager is a `QueryManager` instance, and it doesn't inherit a custom methods of default manager. I propose to complement current implementation of the status managers, to include custom qs/manager methods to a status manager.

Contributor guide

Open the contributing guide

Research direction

Start by reading StatusModel's status-manager setup and QueryManager, then compare how CustomQuerySet.as_manager() exposes methods. Add coverage for Consultation.FINISHED.custom_qs_method() and verify that the status manager retains custom queryset methods while applying the status filter.

Written by the indexing model from the issue text.

Assessment

Tech stack
django, python
Domain
backend, database
Issue type
Feature
Difficulty
3/5
Estimated time
1-2 days
Activity status
Stale
Clarity
Mostly clear
Newbie friendliness
45/100

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.