#21754: Object discrepency between python2.x and python3.x with model field "to_python" and "get_prep_value" when retrieving object from database -------------------------------+-------------------------------------- Reporter: troygrosfield | Owner: nobody Type: Bug | Status: closed Component: Python 3 | Version: 1.6 Severity: Normal | Resolution: fixed Keywords: python3 | Triage Stage: Unreviewed Has patch: 0 | Needs documentation: 0 Needs tests: 0 | Patch needs improvement: 0 Easy pickings: 0 | UI/UX: 0 -------------------------------+-------------------------------------- Changes (by troygrosfield):
* status: new => closed * resolution: => fixed Comment: That did the trick! Thanks @mjtamlyn! Here's the working change for the example above: {{{ from django.utils.six import with_metaclass class IntStoredAsStringField(with_metaclass(models.SubfieldBase, models.CharField)): def __init__(self, max_length=2000, *args, **kwargs): super(IntStoredAsStringField, self).__init__(max_length=max_length, *args, **kwargs) def to_python(self, value): if isinstance(value, int): return value return int(value) def get_prep_value(self, value): return smart_text(value) }}} -- Ticket URL: <https://code.djangoproject.com/ticket/21754#comment:2> 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 post to this group, send email to django-updates@googlegroups.com. To view this discussion on the web visit https://groups.google.com/d/msgid/django-updates/071.afebfdab837f02763074b9fb079fc917%40djangoproject.com. For more options, visit https://groups.google.com/groups/opt_out.