2015-05-07 95 views
1

我正在使用以下代碼。我按照文檔嘗試了所有內容,但找不到任何方法。我錯過了什麼。 models.py包含以下代碼。Django Grappelli自動完成問題

from django.db import models 
from datetime import datetime 
from django.contrib import admin 


class Category(models.Model): 
    category_name = models.CharField(max_length=200) 
    category_id = models.CharField(max_length=200) 

    class Meta: 
     app_label = 'ebay' 

    def __unicode__(self): 
     return u'%s' % (self.category_id) 


class MyCategory(Category): 
    @staticmethod 
    def autocomplete_search_fields(): 
     return ("category_name__icontains", "category_id__icontains") 

    class Meta: 
     proxy = True 


class Listing(models.Model): 
    ebay_id = models.CharField(max_length=200,null=True) 
    amazon_id = models.CharField(max_length=200) 
    category = models.ForeignKey(MyCategory) 

    class Meta: 
     app_label = 'ebay' 

    def __unicode__(self): 
     return u'%s' % (self.ebay_id) 

class ListingOptions(admin.ModelAdmin): 
    # define the raw_id_fields 
    raw_id_fields = ('category',) 
    # define the autocomplete_lookup_fields 
    autocomplete_lookup_fields = { 
     'fk': ['category'], 
    } 

我使用Django版本1.8.1

回答

1

目前,格拉佩利是not yet compatible with Django 1.8。您遇到的問題之一可能是#591

臨時解決方法:

  • 幫助contribute Grappelli
  • 使用Django的1.7.x(含grappelli),但使用Django 1.8的心態。
  • 使用Django 1.8.x的(與django.contrib.admin),並等待格拉佩利
+0

我降級到Django的1.7的下一個版本,但仍是同樣的問題。在安裝django 1.7(使用pip)後降級,刪除安全中間件,在db中添加名稱列(忘記表名),重新運行。沒有發現變化。我需要額外做些什麼 – biztiger

+0

@biztiger你得到的錯誤追溯是什麼?你能用它更新問題嗎? – Yeo

+0

不,沒有一個錯誤,降級後它的工作正常 - 但沒有自動完成(現在是一個選擇框),與1.8相同。 – biztiger