I try to create a custom model field, that should "Converting values to Python
objects" as described in the documentation here:
<https://docs.djangoproject.com/en/dev/howto/custom-model-fields/#converting-values-to-python-objects>
It doesn't work with Python 2.7 and 3.4 with Django 1.7.x and 1.8.x...
I search around and found no unittest case for this "howto/custom-model-fields"
So i created a simple test case to investigate why my code not worked.
I made a unittest against "stable/1.7.x", "stable/1.8.x" and "master" here:
https://github.com/jedie/django/branches/yours
compare links:
stable/1.7.x
<https://github.com/jedie/django/compare/stable/1.7.x...test_custom_model_fields_1.7.x>
stable/1.8.x
<https://github.com/jedie/django/compare/stable/1.8.x...test_custom_model_fields_1.8.x>
master
<https://github.com/jedie/django/compare/master...test_custom_model_fields_master>
I run these test and here the result:
*** 1.7.x with Py2:
test_custom_model_field (custom_model_fields.tests.TestModel1Tests) ... FAIL
test_values (custom_model_fields.tests.TestModel1Tests) ... FAIL
test_custom_model_field (custom_model_fields.tests.TestModel2Tests) ... ok
test_values (custom_model_fields.tests.TestModel2Tests) ... FAIL
*** 1.7.x with Py3:
test_custom_model_field (custom_model_fields.tests.TestModel1Tests) ... FAIL
test_values (custom_model_fields.tests.TestModel1Tests) ... FAIL
test_custom_model_field (custom_model_fields.tests.TestModel2Tests) ... FAIL
test_values (custom_model_fields.tests.TestModel2Tests) ... FAIL
*** 1.8.x with Py2:
test_custom_model_field (custom_model_fields.tests.TestModel1Tests) ... ok
test_values (custom_model_fields.tests.TestModel1Tests) ... ok
*** 1.8.x with Py3
test_custom_model_field (custom_model_fields.tests.TestModel1Tests) ... ok
test_values (custom_model_fields.tests.TestModel1Tests) ... ok
*** master with Py2 - doesn't run:
Traceback (most recent call last):
File "/home/jens/PyLucid_env/src/django/tests/runtests.py", line 12, in
<module>
from django.apps import apps
File "/home/jens/PyLucid_env/src/django/django/apps/__init__.py", line 1, in
<module>
from .config import AppConfig # NOQA
File "/home/jens/PyLucid_env/src/django/django/apps/config.py", line 6, in
<module>
from django.utils.module_loading import module_has_submodule
File "/home/jens/PyLucid_env/src/django/django/utils/module_loading.py", line
4, in <module>
from importlib import import_module
File "/home/jens/PyLucid_env/src/django/django/utils/importlib.py", line 6,
in <module>
ImportError: cannot import name RemovedInDjango19Warning
*** master with Py3:
test_custom_model_field (custom_model_fields.tests.TestModel1Tests) ... ok
test_values (custom_model_fields.tests.TestModel1Tests) ... ok
test_custom_model_field (custom_model_fields.tests.TestModel2Tests) ... ok
test_values (custom_model_fields.tests.TestModel2Tests) ... ok
So the biggest problem is django 1.7.x...
But it should work in the same way:
<https://docs.djangoproject.com/en/1.7/howto/custom-model-fields/#converting-database-values-to-python-objects>
With 1.8.x i must remove the test with existing:
__metaclass__ = models.SubfieldBase
Otherwise the test will not run:
Testing against Django installed in '/home/jens/PyLucid_env/src/django/django'
Importing application custom_model_fields
Traceback (most recent call last):
File "/home/jens/PyLucid_env/src/django/tests/runtests.py", line 448, in
<module>
options.debug_sql)
File "/home/jens/PyLucid_env/src/django/tests/runtests.py", line 235, in
django_tests
state = setup(verbosity, test_labels)
File "/home/jens/PyLucid_env/src/django/tests/runtests.py", line 214, in setup
apps.set_installed_apps(settings.INSTALLED_APPS)
File "/home/jens/PyLucid_env/src/django/django/apps/registry.py", line 324,
in set_installed_apps
self.populate(installed)
File "/home/jens/PyLucid_env/src/django/django/apps/registry.py", line 108,
in populate
app_config.import_models(all_models)
File "/home/jens/PyLucid_env/src/django/django/apps/config.py", line 198, in
import_models
self.models_module = import_module(models_module_name)
File "/usr/lib/python2.7/importlib/__init__.py", line 37, in import_module
__import__(name)
File "/home/jens/PyLucid_env/src/django/tests/custom_model_fields/models.py",
line 41, in <module>
class CommaSeparatedModelField2(CommaSeparatedModelField1):
File
"/home/jens/PyLucid_env/src/django/django/db/models/fields/subclassing.py", line
22, in __new__
RemovedInDjango20Warning)
django.utils.deprecation.RemovedInDjango20Warning: SubfieldBase has been
deprecated. Use Field.from_db_value instead.
Maybe i miss something to handle warnings with tests, but didn't find something
about warnings here:
https://docs.djangoproject.com/en/dev/internals/contributing/writing-code/unit-tests/
--
Mfg.
Jens Diemer
----
http://www.jensdiemer.de
--
You received this message because you are subscribed to the Google Groups "Django
developers (Contributions to Django itself)" group.
To unsubscribe from this group and stop receiving emails from it, send an email
to django-developers+unsubscr...@googlegroups.com.
To post to this group, send email to django-developers@googlegroups.com.
Visit this group at http://groups.google.com/group/django-developers.
To view this discussion on the web visit
https://groups.google.com/d/msgid/django-developers/55804EE4.6060301%40jensdiemer.de.
For more options, visit https://groups.google.com/d/optout.