python - Django Grappelli 自动完成问题

标签 python django django-grappelli

我正在使用以下代码。我按照文档尝试了一切,但找不到任何方法。我是不是错过了什么。 models.py 包含以下代码。

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

最佳答案

目前,Grappelli 是 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)并等待 Grappelli 的下一个版本

关于python - Django Grappelli 自动完成问题,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/30096501/

相关文章:

python - Django 和缓慢的迁移 : how to quickly get an empty database?

django - django grappelli 中的自动完成 - 没有 "add"按钮

python - Django 静态文件在 DEBUG=True 和 `collectstatic` 之后不一致

Django Grappelli Tabular Inline 添加新行 TinyMCE 文本字段不可编辑

python - 无法连接 django 和 Angular 2

python - 在 Google Colab 中将 ipynb notebook 转换为 HTML

python - 检查Boto3版本

python pypi 包模块可见性

python - Django上传excel文件,用pandas处理,下载为csv

python - 如何使用 python 和 lxml 检索某些子元素