Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Autocomplete question #453

Closed
ghost opened this issue Feb 17, 2014 · 20 comments
Closed

Autocomplete question #453

ghost opened this issue Feb 17, 2014 · 20 comments

Comments

@ghost
Copy link

ghost commented Feb 17, 2014

First time to use Grappelli, so please bear with my very native question.
I am intrigued by the autocomplete feature and added
GRAPPELLI_AUTOCOMPLETE_SEARCH_FIELDS = {
"dry_powder": {
"PositionLevelData": ("Position__icontains",)
}
}
into my settings. My understanding is now when I enter partial names of Position in the search field of the changelist page, my typein will be autocompleted. Yet I see nothing like that. Am I misunderstanding something or missing something?
Thanks for the great work.

@sehmaschine
Copy link
Owner

you need to define autocomplets with your ModelAdmin, see http://django-grappelli.readthedocs.org/en/latest/customization.html#autocomplete-lookups

besides, please use the google group for asking questions … this is an issue tracker.

@ghost
Copy link
Author

ghost commented Feb 18, 2014

It seems the autocomplete only works for change-form page. Is there a way to integrate it with search_fields on the change-list page? I do see it is possible with django-autocomplete-light as in
http://django-autocomplete-light.readthedocs.org/en/latest/navigation.html

@sehmaschine
Copy link
Owner

it does work with the changelist … did you try?

@ghost
Copy link
Author

ghost commented Feb 18, 2014

Yes. Sorry if you feel I am wasting your time, but I have spent a day tinkering with this, and yet it just does not work for me. I managed to make the autocomplete show for fk and m2m on the change form page, but not change-list. Here are my snippets, do you see anything missing? Thanks a lot in advance, Yufei

#models.pyclass Place(models.Model): name = models.CharField(max_length=100) parent = models.ForeignKey('self', blank=True, null=True)
def unicode(self): return self.name
@staticmethod def autocomplete_search_fields(): return ('id__iexact', 'name__icontains',)
class Destination(models.Model): places = models.ForeignKey(Place) @staticmethod def autocomplete_search_fields(): return ('id__iexact', 'places__icontains',)

#admin.pyclass DestinationAdmin(admin.ModelAdmin): # The places field is mentioned in a fieldset list_display = ['id', 'places',] search_fields = ['places',] #list_editable = ['places',] # define the raw_id_fields for Autocomplete Lookups raw_id_fields = ('places',) # define the autocomplete_lookup_fields autocomplete_lookup_fields = { 'fk': ['places'] }
class PlaceAdmin(admin.ModelAdmin): list_display=['name',] search_fields = ['name',]
admin.site.register(Destination, DestinationAdmin)admin.site.register(Place, PlaceAdmin)

Date: Tue, 18 Feb 2014 00:04:15 -0800
From: notifications@github.com
To: django-grappelli@noreply.github.com
CC: li_yufei@hotmail.com
Subject: Re: [django-grappelli] Autocomplete question (#453)

it does work with the changelist … did you try?


Reply to this email directly or view it on GitHub.

@sehmaschine
Copy link
Owner

please resend the code in a readable format.

@ghost
Copy link
Author

ghost commented Feb 18, 2014

#models.py
class Place(models.Model):
    name = models.CharField(max_length=100)
    parent = models.ForeignKey('self', blank=True, null=True)

    def __unicode__(self):
        return self.name

    @staticmethod
    def autocomplete_search_fields():
        return ('id__iexact', 'name__icontains',)

class Destination(models.Model):
    places = models.ForeignKey(Place)
    @staticmethod
    def autocomplete_search_fields():
        return ('id__iexact', 'places__icontains',)

#admin.py
class DestinationAdmin(admin.ModelAdmin):
    # The places field is mentioned in a fieldset
    list_display = ['id', 'places',]
    search_fields = ['places',]
    #list_editable = ['places',]
    # define the raw_id_fields for Autocomplete Lookups
    raw_id_fields = ('places',)
    # define the autocomplete_lookup_fields
    autocomplete_lookup_fields = {
        'fk': ['places']
    }

class PlaceAdmin(admin.ModelAdmin):
    list_display=['name',]
    search_fields = ['name',]

admin.site.register(Destination, DestinationAdmin)
admin.site.register(Place, PlaceAdmin)

@sehmaschine
Copy link
Owner

uncomment list_editable — because you want to edit the field, right?

@ghost
Copy link
Author

ghost commented Feb 18, 2014

Not a requirement. Either way autocomplete does not work for me

@sehmaschine
Copy link
Owner

yes, it is a requirement …

you did not overwrite anything (css, templates)?
can you send a screenshot of your changelist?
any js errors?

@ghost
Copy link
Author

ghost commented Feb 18, 2014

Now I do see:
Page not found (404)
Request Method: GET
Request URL: http://127.0.0.1:8000/static/grappelli/jquery/jquery.min.map

Under my \grappelli_example\static\grappelli\jquery:
I see only jquery-1.9.1.min.js

How do I obtain jquery.min.map? Thanks

@sehmaschine
Copy link
Owner

jquery.min.map is not part of grappelli … the question is: why is this file being loaded with your setup?

@ghost
Copy link
Author

ghost commented Feb 18, 2014

no idea. Do you mind if I package my code up and send it over?

@sehmaschine
Copy link
Owner

Sorry – I don´t have time to offer that kind of support. Please try to find out what´s the issue … autocompletes are definitely working on the changelist (I just douple-checked with different browsers).

I'm closing this ticket for now. If you find something, feel free to reopen.

@ghost
Copy link
Author

ghost commented Feb 18, 2014

Understand. Thanks for your kindness.

Date: Tue, 18 Feb 2014 05:28:49 -0800
From: notifications@github.com
To: django-grappelli@noreply.github.com
CC: li_yufei@hotmail.com
Subject: Re: [django-grappelli] Autocomplete question (#453)

Sorry – I don´t have time to offer that kind of support. Please try to find out what´s the issue … autocompletes are definitely working on the changelist (I just douple-checked with different browsers).

I'm closing this ticket for now. If you find something, feel free to reopen.


Reply to this email directly or view it on GitHub.

@ghost
Copy link
Author

ghost commented Feb 18, 2014

just one quick question. How do u think I should go about finding it out? It is a very simple app with not much frills except grappelli. My first instinct is the python package I am using, which is the 64x anaconda for 2.7. I am changing to pythonxy now. Do you think this might be the issue? Any other thoughts will be much appreciated.
Thanks

Date: Tue, 18 Feb 2014 05:28:51 -0800
From: notifications@github.com
To: django-grappelli@noreply.github.com
CC: li_yufei@hotmail.com
Subject: Re: [django-grappelli] Autocomplete question (#453)

Closed #453.


Reply to this email directly or view it on GitHub.

@sehmaschine
Copy link
Owner

I don´t think the python-package is an issue (I might be wrong though).

What I would do:

  1. check if raw_id_fields are working with your changelist (that´s pure django, not related to grappelli).
  2. check if related-lookups (grappelli) are working.

I would use Firefox or Safari for testing. And always check for js-errors.

@ghost
Copy link
Author

ghost commented Feb 18, 2014

I installed pythonxy on the computer without any python installed previously, and get the same results. so it is not the package.

I am wondering why raw_id_fields and related-lookups would not have anything to do here if my goal is to make autocomplete work for the model itself like this:

#models.py
class Place(models.Model):
    name = models.CharField(max_length=100)

    def __unicode__(self):
        return self.name

    @staticmethod
    def autocomplete_search_fields():
        return ('name__icontains',)

#admin.py
class PlaceAdmin(admin.ModelAdmin):
    list_display=['id', 'name',]
    search_fields = ['name',]
    list_editable=['name',]

admin.site.register(Place, PlaceAdmin)

Is this supposed to show autocomplete, as I start typing in the search box? The grappelli package is excellent, but without some examples/videos I do not know what is supposed to work.

Thanks

@eyjolfur12
Copy link

Just a sidenote. I just installed Grappelli (2.5.1) with pip, and I also got a 404 on http://localhost:8000/static/grappelli/jquery/jquery.min.map. So I looked a little into it and found out the request is coming from jquery.min.js, see this ticked: http://stackoverflow.com/questions/18365315/jquerys-jquery-1-10-2-min-map-is-triggering-a-404-not-found.
And thanks for the great work on Grappelli.

@fdemmer
Copy link

fdemmer commented Jul 10, 2014

i came to this issue looking for autocomplete ("suggestions") for search in the change_list.
i think @ymzz277 was looking for the same thing. that is something grappelli does not do!

as @sehmaschine correctly said, the "autocomplete lookups" feature does work in the change_list view. it allows you to edit raw_id fields using the same comfortable, autocompleting search widget as in the change_form view. (you have to add the field to list_display, list_editable and raw_id_fields to make that work)

imho it was unfortunate to call the staticmethod to define the "lookups" for the "autocomplete lookups" feature autocomplete_search_fields() and the setting GRAPPELLI_AUTOCOMPLETE_SEARCH_FIELDS as it has nothing to do with what you can configure in Django admin with search_fields (which is filtering the items listed in change_list by a search term).

autocomplete for the search would be nice... but that is a different story...

@GabrielDumbrava
Copy link

I would also like to have autocomplete working in the search field in the change_list as @fdemmer mentioned. In the meantime I have to rely to other solutions which makes the interface a little inconsistent.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

4 participants