Remove python_2_unicode_compatible method
parent
10f6563852
commit
85469082d0
|
|
@ -1,12 +1,10 @@
|
||||||
from django.db import models
|
from django.db import models
|
||||||
from django.utils.dates import MONTHS_3
|
from django.utils.dates import MONTHS_3
|
||||||
from django.utils.six import python_2_unicode_compatible
|
|
||||||
from django.utils.translation import ugettext_lazy as _
|
from django.utils.translation import ugettext_lazy as _
|
||||||
|
|
||||||
from polymorphic.models import PolymorphicModel
|
from polymorphic.models import PolymorphicModel
|
||||||
|
|
||||||
|
|
||||||
@python_2_unicode_compatible
|
|
||||||
class Order(models.Model):
|
class Order(models.Model):
|
||||||
"""
|
"""
|
||||||
An example order that has polymorphic relations
|
An example order that has polymorphic relations
|
||||||
|
|
@ -23,7 +21,6 @@ class Order(models.Model):
|
||||||
return self.title
|
return self.title
|
||||||
|
|
||||||
|
|
||||||
@python_2_unicode_compatible
|
|
||||||
class Payment(PolymorphicModel):
|
class Payment(PolymorphicModel):
|
||||||
"""
|
"""
|
||||||
A generic payment model.
|
A generic payment model.
|
||||||
|
|
|
||||||
|
|
@ -24,22 +24,3 @@ def with_metaclass(meta, *bases):
|
||||||
return meta(name, bases, d)
|
return meta(name, bases, d)
|
||||||
|
|
||||||
return type.__new__(metaclass, "temporary_class", (), {})
|
return type.__new__(metaclass, "temporary_class", (), {})
|
||||||
|
|
||||||
|
|
||||||
def python_2_unicode_compatible(klass):
|
|
||||||
"""
|
|
||||||
A decorator that defines __unicode__ and __str__ methods under Python 2.
|
|
||||||
Under Python 3 it does nothing.
|
|
||||||
|
|
||||||
To support Python 2 and 3 with a single code base, define a __str__ method
|
|
||||||
returning text and apply this decorator to the class.
|
|
||||||
"""
|
|
||||||
if PY2:
|
|
||||||
if "__str__" not in klass.__dict__:
|
|
||||||
raise ValueError(
|
|
||||||
"@python_2_unicode_compatible cannot be applied "
|
|
||||||
"to %s because it doesn't define __str__()." % klass.__name__
|
|
||||||
)
|
|
||||||
klass.__unicode__ = klass.__str__
|
|
||||||
klass.__str__ = lambda self: self.__unicode__().encode("utf-8")
|
|
||||||
return klass
|
|
||||||
|
|
|
||||||
|
|
@ -6,13 +6,11 @@ from __future__ import unicode_literals
|
||||||
|
|
||||||
from django.db import models
|
from django.db import models
|
||||||
|
|
||||||
from polymorphic.compat import python_2_unicode_compatible
|
|
||||||
from polymorphic.query import PolymorphicQuerySet
|
from polymorphic.query import PolymorphicQuerySet
|
||||||
|
|
||||||
__all__ = ("PolymorphicManager", "PolymorphicQuerySet")
|
__all__ = ("PolymorphicManager", "PolymorphicQuerySet")
|
||||||
|
|
||||||
|
|
||||||
@python_2_unicode_compatible
|
|
||||||
class PolymorphicManager(models.Manager):
|
class PolymorphicManager(models.Manager):
|
||||||
"""
|
"""
|
||||||
Manager for PolymorphicModel
|
Manager for PolymorphicModel
|
||||||
|
|
|
||||||
|
|
@ -4,12 +4,10 @@ import re
|
||||||
from django.db import models
|
from django.db import models
|
||||||
|
|
||||||
from . import compat
|
from . import compat
|
||||||
from .compat import python_2_unicode_compatible
|
|
||||||
|
|
||||||
RE_DEFERRED = re.compile("_Deferred_.*")
|
RE_DEFERRED = re.compile("_Deferred_.*")
|
||||||
|
|
||||||
|
|
||||||
@python_2_unicode_compatible
|
|
||||||
class ShowFieldBase(object):
|
class ShowFieldBase(object):
|
||||||
""" base class for the ShowField... model mixins, does the work """
|
""" base class for the ShowField... model mixins, does the work """
|
||||||
|
|
||||||
|
|
|
||||||
Loading…
Reference in New Issue