Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion .coverage
Original file line number Diff line number Diff line change
@@ -1 +1 @@
!coverage.py: This is a private format, don't read it directly!{"lines": {"/w/_LIB/django-model-to-dict/django_model_to_dict/settings.py": [1, 3, 4, 5, 6, 7, 8, 9, 11, 12, 13, 14, 15, 16, 17], "/w/_LIB/django-model-to-dict/django_model_to_dict/apps.py": [], "/w/_LIB/django-model-to-dict/django_model_to_dict/__init__.py": [1], "/w/_LIB/django-model-to-dict/django_model_to_dict/plugins/__init__.py": [], "/w/_LIB/django-model-to-dict/django_model_to_dict/models.py": [1, 2, 3, 6, 7, 9, 10, 11, 14, 15, 17, 18, 19, 21, 22, 24, 27, 28, 30, 31, 32, 35, 36, 37, 38, 40, 43, 44, 46, 47, 48, 50, 53, 54, 55, 57, 60, 61, 63, 64, 65, 68, 69, 70, 72, 75, 76, 78, 79, 80, 83, 84, 85, 88, 89, 92, 93, 94, 97, 98, 99, 100, 103, 104, 105, 108, 109, 110, 112, 113, 116, 117, 119, 120, 121, 123, 124, 127, 128, 130, 131, 132, 134, 137, 138, 140, 141, 142, 144, 145, 146, 147], "/w/_LIB/django-model-to-dict/django_model_to_dict/plugins/serialization/filebrowser_field.py": [], "/w/_LIB/django-model-to-dict/django_model_to_dict/mixins.py": [256, 1, 5, 264, 265, 267, 268, 271, 272, 273, 274, 275, 276, 280, 281, 282, 283, 285, 286, 287, 288, 291, 292, 293, 294, 296, 297, 298, 299, 302, 303, 304, 305, 307, 308, 309, 310, 312, 315, 316, 317, 318, 319, 320, 321, 322, 324, 325, 326, 327, 328, 329, 330, 331, 332, 334, 335, 336, 337, 338, 339, 340, 341, 342, 344, 349, 350, 351, 354, 355, 356, 140, 142, 143, 144, 161, 163, 166, 169, 172, 175, 178, 179, 182, 183, 184, 185, 186, 189, 190, 191, 192, 193, 196, 197, 198, 199, 203, 207, 210, 211, 212, 213, 214, 215, 216, 217, 218, 221, 223, 226, 229, 232, 234, 235, 236, 238, 239, 240, 242, 243, 244, 246, 248, 250, 254], "/w/_LIB/django-model-to-dict/django_model_to_dict/plugins/serialization/__init__.py": []}}
!coverage.py: This is a private format, don't read it directly!{"lines": {"/mnt/c/Users/Andres/apps/django-model-to-dict/django_model_to_dict/models.py": [1, 2, 3, 6, 7, 9, 10, 11, 14, 15, 17, 18, 19, 21, 22, 24, 27, 28, 30, 31, 32, 35, 36, 37, 38, 40, 43, 44, 46, 47, 48, 50, 53, 54, 55, 57, 60, 61, 63, 64, 65, 68, 69, 70, 72, 75, 76, 78, 79, 80, 83, 84, 85, 88, 89, 92, 93, 94, 97, 98, 99, 100, 103, 104, 105, 108, 110, 112, 113, 116, 117, 119, 120, 121, 123, 124, 127, 128, 130, 131, 132, 134, 137, 138, 140, 141, 142, 144, 145, 146, 147], "/mnt/c/Users/Andres/apps/django-model-to-dict/django_model_to_dict/plugins/serialization/__init__.py": [], "/mnt/c/Users/Andres/apps/django-model-to-dict/django_model_to_dict/__init__.py": [1], "/mnt/c/Users/Andres/apps/django-model-to-dict/django_model_to_dict/apps.py": [], "/mnt/c/Users/Andres/apps/django-model-to-dict/django_model_to_dict/plugins/serialization/filebrowser_field.py": [], "/mnt/c/Users/Andres/apps/django-model-to-dict/django_model_to_dict/mixins.py": [1, 3, 260, 6, 263, 266, 267, 268, 269, 270, 271, 275, 276, 277, 278, 280, 281, 282, 283, 286, 287, 288, 289, 291, 292, 293, 294, 297, 298, 299, 300, 302, 303, 304, 305, 307, 310, 311, 312, 313, 314, 315, 316, 317, 319, 320, 321, 322, 323, 324, 325, 326, 327, 329, 330, 331, 332, 333, 334, 335, 336, 337, 339, 344, 345, 346, 349, 350, 351, 259, 141, 143, 144, 145, 162, 164, 167, 170, 173, 176, 179, 180, 183, 184, 185, 186, 187, 190, 191, 192, 193, 194, 197, 198, 199, 200, 202, 262, 205, 206, 207, 208, 209, 210, 211, 212, 213, 216, 218, 221, 224, 227, 229, 230, 231, 233, 234, 235, 237, 238, 239, 241, 243, 245, 249, 251], "/mnt/c/Users/Andres/apps/django-model-to-dict/django_model_to_dict/settings.py": [1, 3, 4, 5, 6, 7, 8, 9, 11, 12, 13, 14, 15, 16, 17], "/mnt/c/Users/Andres/apps/django-model-to-dict/django_model_to_dict/plugins/__init__.py": []}}
5 changes: 3 additions & 2 deletions django_model_to_dict/mixins.py
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
from .settings import TO_DICT_PREFIXES, TO_DICT_PREFIX_SEPARATOR, TO_DICT_GROUPING,\
TO_DICT_SERIALIZATION_PLUGINS, TO_DICT_SKIP, TO_DICT_POSTFIXES, TO_DICT_POSTFIX_SEPARATOR
from django.utils.module_loading import import_string


class ToDictMixin:
Expand Down Expand Up @@ -198,7 +199,6 @@ def to_dict(self, compress_fields=True, compress_groups=True, compress_prefixes=
result[group][field.name] = self._handle_nontrivial_field(field) or field.value_from_object(self)
continue
# TODO: custom mapping

result[field.name] = self._handle_nontrivial_field(field) or field.value_from_object(self)

# setup empty values for None-valued fields
Expand Down Expand Up @@ -242,7 +242,8 @@ def _handle_nontrivial_field(self, field):

serialization_plugins = getattr(self, 'TO_DICT_SERIALIZATION_PLUGINS', TO_DICT_SERIALIZATION_PLUGINS)

for plugin in serialization_plugins:
for plugin_str in serialization_plugins:
plugin = import_string(plugin_str)()
if plugin.check_field(field):
return plugin.serialize_field(field, self)
return None
Expand Down
6 changes: 3 additions & 3 deletions django_model_to_dict/models.py
Original file line number Diff line number Diff line change
Expand Up @@ -131,7 +131,7 @@ class Meta:
verbose_name = _('Order')
verbose_name_plural = _('Orders')

customer = models.ForeignKey(to=Customer, verbose_name=_('customer'), related_name='orders')
customer = models.ForeignKey(to=Customer, verbose_name=_('customer'), related_name='orders', on_delete=models.CASCADE)


class OrderPosition(models.Model, ToDictMixin):
Expand All @@ -143,5 +143,5 @@ class Meta:

price = models.PositiveIntegerField(verbose_name=_('price'))
quantity = models.PositiveIntegerField(verbose_name=_('quantity'))
product = models.ForeignKey(to=Product, verbose_name=_('product'), related_name='order_positions')
order = models.ForeignKey(to=Order, verbose_name=_('order'), related_name='order_positions')
product = models.ForeignKey(to=Product, verbose_name=_('product'), related_name='order_positions', on_delete=models.CASCADE)
order = models.ForeignKey(to=Order, verbose_name=_('order'), related_name='order_positions', on_delete=models.CASCADE)
2 changes: 1 addition & 1 deletion runtests.py
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@
"ENGINE": "django.db.backends.sqlite3",
}
},
ROOT_URLCONF="django_model_to_dict.urls",
#ROOT_URLCONF="django_model_to_dict.urls",
INSTALLED_APPS=[
"django.contrib.auth",
"django.contrib.contenttypes",
Expand Down
3 changes: 2 additions & 1 deletion tox.ini
Original file line number Diff line number Diff line change
Expand Up @@ -10,4 +10,5 @@ deps =
django-110: Django>=1.10
-r{toxinidir}/requirements_test.txt
basepython =
py34: python3.4
py34: python3.4
py35: python3.5