从django 1.10.6升级到1.11 runserver给出异常

时间:2017-04-05 14:48:22

标签: django django-models django-q django-upgrade django-1.11

在运行服务器上将django从1.10.6升级到1.11后,我遇到了异常。

models.Q继承自tree.Node,在这两个版本中都没有发生重大变化,可能会破坏Q的使用。

class LimitTagAssociations():
    def __init__(self, criteria):
        self.criteria = criteria

    def add_to_query(self, query, aliases):
        query.add_q(models.Q(id__in=[1, 2, 3]))
        query.distinct = True

class Cat(models.Model):
    new_and_now_reco_base = fields.IntegerRangeField(min_value=500, max_value=10000, default=1000)
    auto_taggroups = models.ManyToManyField(TagGroup, null=True, blank=True, limit_choices_to=LimitTagAssociations('1'))
    manual_taggroups = models.ManyToManyField(TagGroup, null=True, blank=True, limit_choices_to=LimitTagAssociations('2'))
    abs_url = models.CharField(max_length=255, blank=True, null=True)
    primary_filter_select = models.ManyToManyField(TagGroup, null=True, blank=True, limit_choices_to=LimitTagAssociations('3'))

class CatAdminForm(forms.ModelForm):
    class Meta:
        model = Cat
        exclude = ()



Traceback (most recent call last):
  File "/srv/webapps/myproj.com/virtualenvs/myproj/local/lib/python2.7/site-packages/django/utils/autoreload.py", line 227, in wrapper
    fn(*args, **kwargs)
  File "/srv/webapps/myproj.com/virtualenvs/myproj/local/lib/python2.7/site-packages/django/core/management/commands/runserver.py", line 117, in inner_run
    autoreload.raise_last_exception()
  File "/srv/webapps/myproj.com/virtualenvs/myproj/local/lib/python2.7/site-packages/django/utils/autoreload.py", line 250, in raise_last_exception
    six.reraise(*_exception)
  File "/srv/webapps/myproj.com/virtualenvs/myproj/local/lib/python2.7/site-packages/django/utils/autoreload.py", line 227, in wrapper
    fn(*args, **kwargs)
  File "/srv/webapps/myproj.com/virtualenvs/myproj/local/lib/python2.7/site-packages/django/__init__.py", line 27, in setup
    apps.populate(settings.INSTALLED_APPS)
  File "/srv/webapps/myproj.com/virtualenvs/myproj/local/lib/python2.7/site-packages/django/apps/registry.py", line 116, in populate
    app_config.ready()
  File "/srv/webapps/myproj.com/virtualenvs/myproj/local/lib/python2.7/site-packages/django/contrib/admin/apps.py", line 23, in ready
    self.module.autodiscover()
  File "/srv/webapps/myproj.com/virtualenvs/myproj/local/lib/python2.7/site-packages/django/contrib/admin/__init__.py", line 26, in autodiscover
    autodiscover_modules('admin', register_to=site)
  File "/srv/webapps/myproj.com/virtualenvs/myproj/local/lib/python2.7/site-packages/django/utils/module_loading.py", line 50, in autodiscover_modules
    import_module('%s.%s' % (app_config.name, module_to_search))
  File "/usr/lib/python2.7/importlib/__init__.py", line 38, in import_module
    __import__(name)
  File "/srv/webapps/myproj.com/myproj/product/admin.py", line 6, in <module>
    from product.forms import ProdFilterForm, BrandAdminForm
  File "/srv/webapps/myproj.com/myproj/product/forms.py", line 124, in <module>
    class CatAdminForm(forms.ModelForm):
  File "/srv/webapps/myproj.com/virtualenvs/myproj/local/lib/python2.7/site-packages/django/forms/models.py", line 252, in __new__
    opts.field_classes)
  File "/srv/webapps/myproj.com/virtualenvs/myproj/local/lib/python2.7/site-packages/django/forms/models.py", line 177, in fields_for_model
    formfield.queryset = formfield.queryset.complex_filter(limit_choices_to)
  File "/srv/webapps/myproj.com/virtualenvs/myproj/local/lib/python2.7/site-packages/django/db/models/query.py", line 814, in complex_filter
    clone.query.add_q(filter_obj)
  File "/srv/webapps/myproj.com/virtualenvs/myproj/local/lib/python2.7/site-packages/django/db/models/sql/query.py", line 1260, in add_q
    clause, _ = self._add_q(q_object, self.used_aliases)
  File "/srv/webapps/myproj.com/virtualenvs/myproj/local/lib/python2.7/site-packages/django/db/models/sql/query.py", line 1270, in _add_q
    connector = q_object.connector
AttributeError: LimitTagAssociations instance has no attribute 'connector'

0 个答案:

没有答案