#30931: Cannot override get_FOO_display() in Django 2.2+. -------------------------------------+------------------------------------- Reporter: Jim Ouwerkerk | Owner: Carlton | Gibson Type: Bug | Status: assigned Component: Database layer | Version: 2.2 (models, ORM) | Severity: Release blocker | Resolution: Keywords: | Triage Stage: Accepted Has patch: 0 | Needs documentation: 0 Needs tests: 0 | Patch needs improvement: 0 Easy pickings: 0 | UI/UX: 0 -------------------------------------+-------------------------------------
Comment (by Sergey Fedoseev): I don't think it should be marked as blocker since it looks like it was never supported, because it depends on the order of `attrs` passed in `ModelBase.__new__()`. So on Django 2.1 and Python 3.7: {{{ In [1]: import django ...: django.VERSION In [2]: from django.db import models ...: ...: class FooBar(models.Model): ...: def get_foo_bar_display(self): ...: return "something" ...: ...: foo_bar = models.CharField("foo", choices=[(1, 'foo'), (2, 'bar')]) ...: ...: def __str__(self): ...: return self.get_foo_bar_display() # This returns 'foo' or 'bar' in 2.2, but 'something' in 2.1 ...: ...: class Meta: ...: app_label = 'test' ...: ...: FooBar(foo_bar=1) Out[2]: <FooBar: foo> }}} Before [https://docs.python.org/3.8/whatsnew/3.6.html#whatsnew36-pep520 Python 3.6] the order of `attrs` wasn't defined at all. -- Ticket URL: <https://code.djangoproject.com/ticket/30931#comment:4> Django <https://code.djangoproject.com/> The Web framework for perfectionists with deadlines. -- You received this message because you are subscribed to the Google Groups "Django updates" group. To unsubscribe from this group and stop receiving emails from it, send an email to django-updates+unsubscr...@googlegroups.com. To view this discussion on the web visit https://groups.google.com/d/msgid/django-updates/070.c274a0de169d57f14f6d5358a2e7e4a2%40djangoproject.com.