Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Extend source model's QuerySet manager to Historical model? #963

Closed
dwasyl opened this issue Mar 24, 2022 · 4 comments · Fixed by #1306
Closed

Extend source model's QuerySet manager to Historical model? #963

dwasyl opened this issue Mar 24, 2022 · 4 comments · Fixed by #1306

Comments

@dwasyl
Copy link

dwasyl commented Mar 24, 2022

Getting ahead of myself on this great unreleased feature, but..

Based on the great work added in #866, is it at all possible to extend the object manager from the source model to the Historical model? The idea here is that now that as_of() returns a HistoricalQuerySet most of the filtering I want to do on the historical models is based on filtering I would do on live objects.

Since a custom ModelManager or QuerySetManager that provides chainable filters would work on historical models, to avoid repeating them again, is there a way to use the same manager on the HistoricalModel?

@tim-schilling
Copy link
Contributor

@dwasyl can you take a look at #1306 to see if it will solve your concern?

@dwasyl
Copy link
Author

dwasyl commented Feb 13, 2024

@tim-schilling it looks like a reasonable approach to the same problem. Only thing I forget is needing (in some cases a lot of) duplicated code to bring the queryset classes over from the live one (but that might be unavoidable). Excited to see something like this!

@tim-schilling
Copy link
Contributor

@dwasyl Ah, I think I covered that in the docs:

class QuestionQuerySet(HistoricalQuerySet):
    def question_prefixed(self):
        return self.filter(question__startswith='Question: ')

class HistoryQuestionQuerySet(QuestionQuerySet, HistoricalQuerySet):
    """Redefine QuerySet with base class HistoricalQuerySet"""

class Question(models.Model):
    pub_date = models.DateTimeField('date published')
    history = HistoricalRecords(historical_queryset=HistoryQuestionQuerySet)
    manager = models.Manager.from_queryset(QuestionQuerySet)()

@dwasyl
Copy link
Author

dwasyl commented Feb 13, 2024

That's what I get for giving it only a quick look!

I wasn't familiar with the models.Manager.from_queryset() notation style before either so that's a good tip either way.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
2 participants