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

Add FieldOpts type alias to django_stubs_ext #1960

Open
CarrotManMatt opened this issue Feb 20, 2024 · 2 comments
Open

Add FieldOpts type alias to django_stubs_ext #1960

CarrotManMatt opened this issue Feb 20, 2024 · 2 comments
Labels
bug Something isn't working

Comments

@CarrotManMatt
Copy link

Bug report

What's wrong

Similar to the existing type aliases defined within django_stubs_ext (E.g. StrPromise), it would be useful to have the FieldOpts type alias exposed for type checking the get_fieldsets() method of a ModelAdmin

How it should work

from typing import TypeAlias, TypeVar

from django.contrib.admin import ModelAdmin
from django.db.models import Model
from django_stubs_ext import FieldOpts

T_model = TypeVar("T_model", bound=Model)
Fieldsets: TypeAlias = list[tuple[str | StrPromise | None, FieldOpts]] | tuple[tuple[str | StrPromise | None, FieldOpts], ...] | tuple[()]

class CustomModelAdmin(ModelAdmin[T_model]):
    @override
    def get_fieldsets(self, request: HttpRequest, obj: T_model | None = None) -> Fieldsets:
        ...

System information

  • OS: Windows 10 Home 22H2 19045.4046
  • python version: 3.12.1
  • django version: 4.2.10
  • mypy version: 1.7.1
  • django-stubs version: 4.2.7
  • django-stubs-ext version: 4.2.7
@CarrotManMatt CarrotManMatt added the bug Something isn't working label Feb 20, 2024
@sobolevn
Copy link
Member

You mean this one?

class _FieldOpts(_OptionalFieldOpts, total=True):

@CarrotManMatt
Copy link
Author

I think so, I'm currently importing from django.contrib.admin.options import _FieldOpts

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bug Something isn't working
Development

No branches or pull requests

2 participants