Fix ugettext_lazy objects in Choice tuples not being evaluated. Running .format() on it will return the string we want, and wont cause any problems when its run on a string without arguments

This commit is contained in:
Jacob Klapwijk 2016-05-31 15:56:33 +02:00
parent 0f94f2b2ef
commit be449ab1c0
2 changed files with 8 additions and 1 deletions

View File

@ -1,6 +1,12 @@
from __future__ import absolute_import
from django.db import models
from django.utils.translation import ugettext_lazy as _
CHOICES = (
(1, 'this'),
(2, _('that'))
)
class Pet(models.Model):
@ -22,6 +28,7 @@ class Reporter(models.Model):
last_name = models.CharField(max_length=30)
email = models.EmailField()
pets = models.ManyToManyField('self')
a_choice = models.CharField(max_length=30, choices=CHOICES)
def __str__(self): # __unicode__ on Python 2
return "%s %s" % (self.first_name, self.last_name)

View File

@ -18,4 +18,4 @@ def to_snake_case(name):
def to_const(string):
return re.sub('[\W|^]+', '_', string).upper()
return re.sub('[\W|^]+', '_', string.format()).upper()