2014-08-28 51 views
1

執行:不能凍結場

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 

我的問題是如何定義("null": ["null", {{"ignore_if": "name"}],)模型這一行的.py。

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' 

south.aeracode.org/ticket/422

+0

有沒有解決這個問題?現在正是這個問題(試圖覆蓋TaggableManager) – straykiwi 2015-03-30 21:33:16

回答

0

https://django-taggit.readthedocs.org/en/latest/api.html 你也可以繼承_TaggableManager(注意下劃線)來添加方法或功能。 TaggableManager爲您的自定義類使用可選的管理關鍵字參數,如下所示:

class Food(models.Model): 
    # ... fields here 
    tags = TaggableManager(manager=_CustomTaggableManager)