1

I am using the following code. I tried everything as per docs, but can't find any way. Am I missing something. The models.py contains the following code.

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'],
    }

I am using Django version 1.8.1

biztiger
  • 1,447
  • 4
  • 23
  • 40

1 Answers1

1

At the moment, Grappelli is not yet compatible with Django 1.8. One of the issue that you encounter could be #591.

Temporary solution:

  • help to contribute Grappelli
  • use Django 1.7.x (with grappelli) but with Django 1.8 mindset.
  • use django 1.8.x (with django.contrib.admin) and wait for next release of Grappelli
Yeo
  • 11,416
  • 6
  • 63
  • 90
  • I downgraded to Django 1.7, but still the same issue. To downgrade after installing django 1.7(using pip), removed security middleware, added name column in db(forget the tablename), rerun. no changes noticed. Do I need to do anything extra – biztiger May 07 '15 at 09:52
  • @biztiger what is the error traceback you got? can you update the question with it. – Yeo May 07 '15 at 10:09
  • No, not a single error, after downgrading it's working fine - but just without autocomplete(now a select box), same as 1.8. – biztiger May 07 '15 at 10:14
  • @biztiger I notice you are using Proxy models perhaps this might be the issue. Could you try to change `autocomplete_lookup_fields` from `'fk': ['category'],` into `'fk': ['mycategory'],` ? – Yeo May 07 '15 at 10:26
  • No change, but I believe it should be category rather than mycategory, since that's the name of the foreign key in listing model – biztiger May 07 '15 at 10:33
  • forget to mention to change all your `category` to `mycategory`... Because you are using `ForeignKey(MyCategory)`. Is that still not working? – Yeo May 07 '15 at 10:35
  • I have removed the proxy class altogether, no change. – biztiger May 07 '15 at 10:59