From 16a5a2a2c8d8dbf9cc3e033dd84b986bcaadb963 Mon Sep 17 00:00:00 2001 From: Joshua Cannon Date: Fri, 4 Jan 2019 14:03:53 -0600 Subject: Fixed #30076 -- Added Model.get_FOO_display() even if field's choices are empty. --- tests/model_fields/models.py | 16 ++++++++++++++++ 1 file changed, 16 insertions(+) (limited to 'tests/model_fields/models.py') diff --git a/tests/model_fields/models.py b/tests/model_fields/models.py index 13d4843632..02fea36b31 100644 --- a/tests/model_fields/models.py +++ b/tests/model_fields/models.py @@ -50,6 +50,14 @@ class Whiz(models.Model): c = models.IntegerField(choices=CHOICES, null=True) +class WhizDelayed(models.Model): + c = models.IntegerField(choices=(), null=True) + + +# Contrived way of adding choices later. +WhizDelayed._meta.get_field('c').choices = Whiz.CHOICES + + class WhizIter(models.Model): c = models.IntegerField(choices=iter(Whiz.CHOICES), null=True) @@ -58,6 +66,14 @@ class WhizIterEmpty(models.Model): c = models.CharField(choices=iter(()), blank=True, max_length=1) +class Choiceful(models.Model): + no_choices = models.IntegerField(null=True) + empty_choices = models.IntegerField(choices=(), null=True) + with_choices = models.IntegerField(choices=[(1, 'A')], null=True) + empty_choices_bool = models.BooleanField(choices=()) + empty_choices_text = models.TextField(choices=()) + + class BigD(models.Model): d = models.DecimalField(max_digits=32, decimal_places=30) -- cgit v1.3