2017-06-05 4 views
0

私はカテゴリフィールドは大丈夫であることを証明し、'name', 'category', 'value_type', 'help_text'フィールドを見ることができ、管理インターフェースで変更リストを表示します。しかし、パラメータをクリックして変更フォームにアクセスすると、上記のエラーが発生します。django admin "KeyPasswordForm"にキーのカテゴリがありません。選択肢はhelp_text、name、units、value_typeです。 "

は、ここに私の管理者です:

@admin.register(SpecificationParameter) 
class SpecificationParameterAdmin(SortableAdminMixin, admin.ModelAdmin): 
    """ 
    For administering Specification Parameters 
    """ 
    # Fields shown in lists 
    list_display = ('name', 'category', 'value_type', 'help_text') 
    list_per_page = 20 
    # related field needs __ due to foreign key 
    search_fields = ['name', 'category__name'] 
    # Change 'Save and add another' to 'Save as new' to easily create similar entries 
    save_as = True 
    # django 1.10 will default to staying on the page after creating a new one; redirects in 1.9 :(
    # for this purpose, show the id 
    readonly_fields = ('id',) 
    # Modify the layout of the form, put the optional choices last 
    fieldsets = (
     (None,  {'fields': (('name', 'id'), 'category', 'units', 'help_text')}), 
     (_('Type'), {'fields': ('value_type',)}), 
    ) 
    inlines = [SpecificationValueChoiceAdminInline] 

    def get_inline_instances(self, request, obj=None): 
     """ 
     Override to dynamically display choices if multiple choice or checkbox 
     """ 
     instances = [] 
     for inline in self.inlines: 
      if inline == SpecificationValueChoiceAdminInline: 
       if obj and obj.value_type in (tup[0] for tup in SpecificationParameter.VALUE_TYPES[1][1]): 
        # for changes and not adds 
        instances += [inline(self.model, self.admin_site)] 
      else: 
       instances += [inline(self.model, self.admin_site)] 
     return instances 

、関連するモデルの抜粋:それはForeignKeyのだから

class SpecificationParameter(models.Model): 
    """ 
    The fields required by parameters in the specification of a product. 
    """ 
    # _() Provides the name as a translation 
    name = models.CharField(_("specification parameter name (public)"), unique=True, max_length=50, 
     help_text=_("Be as specific as you can, for example: Minimum DC Voltage")) 
    # All parameters in a category need to be removed manually before it will allow you to delete the cetegory 
    category = models.ForeignKey(SpecificationCategory, verbose_name=_("parameter category"), on_delete=models.PROTECT, 
     help_text=_("Add a new or select an existing parameter section")) 
    help_text = models.CharField(_("help text"), max_length=160, help_text=_("Specify any additional information useful to the staff entering values"), blank=True) 
    .... 

Traceback

それがだろうか? アイデアを大いに感謝します。

EDIT:fieldsetsを削除

はエラーを削除しますが、デフォルトのフィールドはcategoryが含まれていません。

私は上記の、違いはありませんとジャンゴ1.10.7および1.9.9でその削除コメントを試してみました。私が行った変更でなければなりません: - /私はこのミックスインで使用されているモデルのメタordering属性である。これはcategory以来SortableAdminMixinによって引き起こされたform.base_fields

+0

フルトレースバック、および 'SpecificationParameter'モデルを提示してください。 – Alasdair

+0

'self.inlines'の変更はスレッドセーフではないことに注意してください。それは上書きする方が良いだろう[ 'get_inline_instances'](https://でdocs.djangoproject.com/EN/1.11/REFに/ contrib /管理/#django.contrib.admin.ModelAdmin.get_inline_instances')。 – Alasdair

+0

私は異常を見ることができ、それはhelp_textです、あなたはその名前のフィールドを持っていますか?そうでなければ、あなたのモデルに問題があります。djangoは、名前フィールドに定義されたhelp_textを別のフィールドとして扱うのはどうですか? – Exprator

答えて

1

には表示されませんcategory確認しています。

私はpip install -Uを行ったとき、私は誤って変更された分岐を上書きしていました。

関連する問題