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

Methods generated by order_with_respect_to (models) #2037

Open
HiPhish opened this issue Mar 31, 2024 · 0 comments
Open

Methods generated by order_with_respect_to (models) #2037

HiPhish opened this issue Mar 31, 2024 · 0 comments
Labels
enhancement New feature or request mypy-plugin Issues specific to mypy_django_plugin

Comments

@HiPhish
Copy link

HiPhish commented Mar 31, 2024

Bug report

What's wrong

It is possible to set the order of model instances relative to some other model (such as order of answers to a question in a questionnaire) by specifying order_with_respect_to in a model's Meta class: https://docs.djangoproject.com/en/5.0/ref/models/options/#order-with-respect-to

Doing so generates four new methods in total:

  • On the first model
    • get_next_in_order
    • get_previous_in_order
  • On the other model
    • get_RELATED_order (where RELATED is the name of the first model)
    • set_RELATED_order

However, these methods are not recognized by django-stubs, I get an error as if I had a typo. Making the Meta class inherit from TypedModelMeta has no effect.

How is that should be

These four methods should be recognized, along with the correct type for the primary key. This means the get method returns a QuerySet of whatever type the PK is, and the set method takes an Iterable of whatever the type of the PK is. The next and previous methods return an instance of whatever their model is. They do loop around, so there will always be an object.

System information

  • OS: Void Linux
  • python version: 3.12.2
  • django version: 5.0.3
  • mypy version: 1.9.0
  • django-stubs version: 4.2.7
  • django-stubs-ext version: 4.2.7
@HiPhish HiPhish added the bug Something isn't working label Mar 31, 2024
@intgr intgr added enhancement New feature or request mypy-plugin Issues specific to mypy_django_plugin and removed bug Something isn't working labels Mar 31, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
enhancement New feature or request mypy-plugin Issues specific to mypy_django_plugin
Development

No branches or pull requests

2 participants