Anonymous avatar Anonymous committed 49e1828

Fixed string lowercase problem in modeltests.custom_pk

Comments (0)

Files changed (1)

tests/modeltests/custom_pk/fields.py

-import random
-import string
-
-from django.db import models
-
-class MyWrapper(object):
-    def __init__(self, value):
-        self.value = value
-
-    def __repr__(self):
-        return "<%s: %s>" % (self.__class__.__name__, self.value)
-
-    def __unicode__(self):
-        return self.value
-
-    def __eq__(self, other):
-        if isinstance(other, self.__class__):
-            return self.value == other.value
-        return self.value == other
-
-class MyAutoField(models.CharField):
-    __metaclass__ = models.SubfieldBase
-
-    def __init__(self, *args, **kwargs):
-        kwargs['max_length'] = 10
-        super(MyAutoField, self).__init__(*args, **kwargs)
-
-    def pre_save(self, instance, add):
-        value = getattr(instance, self.attname, None)
-        if not value:
-            value = MyWrapper(''.join(random.sample(string.ascii_lowercase, 10)))
-            setattr(instance, self.attname, value)
-        return value
-
-    def to_python(self, value):
-        if not value:
-            return
-        if not isinstance(value, MyWrapper):
-            value = MyWrapper(value)
-        return value
-
-    def get_db_prep_save(self, value):
-        if not value:
-            return
-        if isinstance(value, MyWrapper):
-            return unicode(value)
-        return value
-
-    def get_db_prep_value(self, value):
-        if not value:
-            return
-        if isinstance(value, MyWrapper):
-            return unicode(value)
-        return value
Tip: Filter by directory path e.g. /media app.js to search for public/media/app.js.
Tip: Use camelCasing e.g. ProjME to search for ProjectModifiedEvent.java.
Tip: Filter by extension type e.g. /repo .js to search for all .js files in the /repo directory.
Tip: Separate your search with spaces e.g. /ssh pom.xml to search for src/ssh/pom.xml.
Tip: Use ↑ and ↓ arrow keys to navigate and return to view the file.
Tip: You can also navigate files with Ctrl+j (next) and Ctrl+k (previous) and view the file with Ctrl+o.
Tip: You can also navigate files with Alt+j (next) and Alt+k (previous) and view the file with Alt+o.