将 Django 1.6 升级到 1.7。 "related_name" 的通用关系是否有任何变化?
Upgrading django 1.6 to 1.7. Is there any change in Generic relations for "related_name"?
我正在尝试将一个项目从 Django 1.6 升级到 1.7。当我尝试 运行 服务器时,我得到 "TypeError: init() got an unexpected keyword argument 'related_name'":
$ ./manage.py runserver --settings=bertondealer.settings.local 0.0.0.0:8000
Traceback (most recent call last):
File "./manage.py", line 10, in <module>
execute_from_command_line(sys.argv)
File "/home/vagrant/.virtualenvs/dealer17/local/lib/python2.7/site-packages/django/core/management/__init__.py", line 385, in execute_from_command_line
utility.execute()
File "/home/vagrant/.virtualenvs/dealer17/local/lib/python2.7/site-packages/django/core/management/__init__.py", line 354, in execute
django.setup()
File "/home/vagrant/.virtualenvs/dealer17/local/lib/python2.7/site-packages/django/__init__.py", line 21, in setup
apps.populate(settings.INSTALLED_APPS)
File "/home/vagrant/.virtualenvs/dealer17/local/lib/python2.7/site-packages/django/apps/registry.py", line 108, in populate
app_config.import_models(all_models)
File "/home/vagrant/.virtualenvs/dealer17/local/lib/python2.7/site-packages/django/apps/config.py", line 197, 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 "/vagrant_data/projects/companyapps/clientes/models.py", line 3, in <module>
from distribuidores.models import Empresa as Distribuidor
File "/vagrant_data/projects/companyapps/distribuidores/models.py", line 50, in <module>
class Empresa(models.Model):
File "/vagrant_data/projects/companyapps/distribuidores/models.py", line 88, in Empresa
eventos = generic.GenericRelation(Evento, related_name='distribuidores_set')
File "/home/vagrant/.virtualenvs/dealer17/local/lib/python2.7/site-packages/django/contrib/contenttypes/fields.py", line 266, in __init__
from_fields=[self.object_id_field_name], **kwargs)
File "/home/vagrant/.virtualenvs/dealer17/local/lib/python2.7/site-packages/django/db/models/fields/related.py", line 1309, in __init__
super(ForeignObject, self).__init__(**kwargs)
TypeError: __init__() got an unexpected keyword argument 'related_name'
这与 Django 1.7 中的任何更改有关吗?
GenericKey 没有 related_name
。
但是在 django 1.7
中你可以使用 related_query_name
而不是 related_name
我正在尝试将一个项目从 Django 1.6 升级到 1.7。当我尝试 运行 服务器时,我得到 "TypeError: init() got an unexpected keyword argument 'related_name'":
$ ./manage.py runserver --settings=bertondealer.settings.local 0.0.0.0:8000
Traceback (most recent call last):
File "./manage.py", line 10, in <module>
execute_from_command_line(sys.argv)
File "/home/vagrant/.virtualenvs/dealer17/local/lib/python2.7/site-packages/django/core/management/__init__.py", line 385, in execute_from_command_line
utility.execute()
File "/home/vagrant/.virtualenvs/dealer17/local/lib/python2.7/site-packages/django/core/management/__init__.py", line 354, in execute
django.setup()
File "/home/vagrant/.virtualenvs/dealer17/local/lib/python2.7/site-packages/django/__init__.py", line 21, in setup
apps.populate(settings.INSTALLED_APPS)
File "/home/vagrant/.virtualenvs/dealer17/local/lib/python2.7/site-packages/django/apps/registry.py", line 108, in populate
app_config.import_models(all_models)
File "/home/vagrant/.virtualenvs/dealer17/local/lib/python2.7/site-packages/django/apps/config.py", line 197, 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 "/vagrant_data/projects/companyapps/clientes/models.py", line 3, in <module>
from distribuidores.models import Empresa as Distribuidor
File "/vagrant_data/projects/companyapps/distribuidores/models.py", line 50, in <module>
class Empresa(models.Model):
File "/vagrant_data/projects/companyapps/distribuidores/models.py", line 88, in Empresa
eventos = generic.GenericRelation(Evento, related_name='distribuidores_set')
File "/home/vagrant/.virtualenvs/dealer17/local/lib/python2.7/site-packages/django/contrib/contenttypes/fields.py", line 266, in __init__
from_fields=[self.object_id_field_name], **kwargs)
File "/home/vagrant/.virtualenvs/dealer17/local/lib/python2.7/site-packages/django/db/models/fields/related.py", line 1309, in __init__
super(ForeignObject, self).__init__(**kwargs)
TypeError: __init__() got an unexpected keyword argument 'related_name'
这与 Django 1.7 中的任何更改有关吗?
GenericKey 没有 related_name
。
但是在 django 1.7
中你可以使用related_query_name
而不是 related_name