add support for get_FIELD_display for choices fields

This commit is contained in:
Maxim Kurnikov
2019-07-19 02:39:39 +03:00
parent bba6f769b5
commit 1721c997be
2 changed files with 38 additions and 0 deletions

View File

@@ -0,0 +1,20 @@
- case: if_field_has_choices_set_model_has_get_FIELDNAME_display_method
main: |
from myapp.models import MyUser
user = MyUser(name='user', gender='M')
user.get_name_display() # E: "MyUser" has no attribute "get_name_display"; maybe "get_gender_display"?
reveal_type(user.get_gender_display()) # N: Revealed type is 'builtins.str'
installed_apps:
- myapp
files:
- path: myapp/__init__.py
- path: myapp/models.py
content: |
from django.db import models
GENDER_CHOICES = (
('M', 'Male'),
('F', 'Female'),
)
class MyUser(models.Model):
name = models.CharField(max_length=100)
gender = models.CharField(max_length=100, choices=GENDER_CHOICES)