1

Little bit strange story:

I implemented overriding methods of get_FOO_display() and it WORKED but suddenly it stopped! I mean I see that my methods are skip and only django implemented methods work. I can't find why. I compare code from other commits (git) and nothing what could influence on this. What it's funny when I revert commits it works again.

Yes I know you will say that I overlooked sth, but I checked code few times, my friends checked code as well and nothing.

I just hope that someone has similar problem and show how to handle or someone knows why it could stop work.

This is part of my code:

class UserProfile(models.Model):
    marital_status = models.IntegerField(
       verbose_name=_('stan cywilny'),
       choices=i18n_const.MARITAL_STATUS_CHOICES,
       null=True, blank=True, default=None)

    def get_marital_status_display(self):
        if self.user.is_woman:
            i18n = dict(i18n_const.MARITAL_STATUS_CHOICES_WOMAN)
        else:
            i18n = dict(i18n_const.MARITAL_STATUS_CHOICES)
        if self.martial_status is not None:
            return force_text(i18n[self.marital_status])
        else:
            return ''
Cœur
  • 37,241
  • 25
  • 195
  • 267
kspacja
  • 4,648
  • 11
  • 38
  • 41

1 Answers1

0

Simply overriding it never worked for me. The function get_FOO_display is created after the models are loaded so it may be overwritten by django.

Check my answer here for a solution that worked for me.

user2111922
  • 891
  • 9
  • 9