diff options
author | Marc Tamlyn <marc.tamlyn@gmail.com> | 2014-08-12 13:08:40 +0100 |
---|---|---|
committer | Marc Tamlyn <marc.tamlyn@gmail.com> | 2014-09-03 20:36:03 +0100 |
commit | e9103402c0fa873aea58a6a11dba510cd308cb84 (patch) | |
tree | 947a946de6d7354f22e8c5ec7a98ecc37c98eb08 /tests/custom_pk | |
parent | 89559bcfb096ccc625e0e9ab41e2136fcb32a514 (diff) | |
download | django-e9103402c0fa873aea58a6a11dba510cd308cb84.tar.gz |
Fixed #18757, #14462, #21565 -- Reworked database-python type conversions
Complete rework of translating data values from database
Deprecation of SubfieldBase, removal of resolve_columns and
convert_values in favour of a more general converter based approach and
public API Field.from_db_value(). Now works seamlessly with aggregation,
.values() and raw queries.
Thanks to akaariai in particular for extensive advice and inspiration,
also to shaib, manfre and timograham for their reviews.
Diffstat (limited to 'tests/custom_pk')
-rw-r--r-- | tests/custom_pk/fields.py | 7 |
1 files changed, 6 insertions, 1 deletions
diff --git a/tests/custom_pk/fields.py b/tests/custom_pk/fields.py index 2aa3bad963..1f3265952a 100644 --- a/tests/custom_pk/fields.py +++ b/tests/custom_pk/fields.py @@ -23,7 +23,7 @@ class MyWrapper(object): return self.value == other -class MyAutoField(six.with_metaclass(models.SubfieldBase, models.CharField)): +class MyAutoField(models.CharField): def __init__(self, *args, **kwargs): kwargs['max_length'] = 10 @@ -43,6 +43,11 @@ class MyAutoField(six.with_metaclass(models.SubfieldBase, models.CharField)): value = MyWrapper(value) return value + def from_db_value(self, value, connection): + if not value: + return + return MyWrapper(value) + def get_db_prep_save(self, value, connection): if not value: return |