执行:
python ./mamage.py schemamigration --initial<br>
它给了我一个错误:
! Cannot freeze field 'exam.question.tags'
! (this field has class taggit_autocomplete_modified.managers.TaggableManagerAutocomplete)
! South cannot introspect some fields; this is probably because they are custom
! fields. If they worked in 0.6 or below, this is because we have removed the
! models parser (it often broke things).
! To fix this, read http://south.aeracode.org/wiki/MyFieldsDontWork
自定义字段类:
from django.utils.translation import ugettext_lazy as _
from taggit.forms import TagField
from taggit.managers import TaggableManager
from widgets import TagAutocomplete
class TaggableManagerAutocomplete(TaggableManager):
def formfield(self, form_class=TagField, **kwargs):
field = super(TaggableManagerAutocomplete, self).formfield(form_class, **kwargs)
field.widget = TagAutocomplete()
return field
我的问题是如何在model.py中定义( "null": ["null", {{"ignore_if": "name"}],)
这一行。
from south.modelsinspector import add_introspection_rules
from taggit_autocomplete_modified.managers import TaggableManagerAutocomplete
add_introspection_rules(
[
(
(TaggableManagerAutocomplete, ),
[],
{
"null": ["null", {{"ignore_if": "name"}],
},
),
],
["^taggit_autocomplete_modified\.managers\.TaggableManagerAutocomplete"])
如果没有定义此行,我将收到另一个错误:
TypeError: __init__() got an unexpected keyword argument 'null'
答案 0 :(得分:0)
https://django-taggit.readthedocs.org/en/latest/api.html 您可以继承_TaggableManager(注意下划线)以添加方法或功能。 TaggableManager为您的自定义类提供可选的manager关键字参数,如下所示:
class Food(models.Model):
# ... fields here
tags = TaggableManager(manager=_CustomTaggableManager)