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

“X” and “pencil” icon 404 #145

Open
mhulse opened this issue Apr 12, 2015 · 6 comments
Open

“X” and “pencil” icon 404 #145

mhulse opened this issue Apr 12, 2015 · 6 comments
Labels

Comments

@mhulse
Copy link

mhulse commented Apr 12, 2015

Hello,

Thanks for this awesome plugin (I'm using 0.9.0, Django 1.7.4 and Python 3.4.x).

Not sure if this is a feature or if I have things not fully setup/functional, but I noticed if I type-in a non-existent value (and the text turns red) and click the pencil icon or the red X buttons, I get a 404 page.

screen shot 2015-04-11 at 11 12 40 pm

Logically, I get why this happens. For folks that are not geeks, this could be confusing.

It would be pretty cool if the X and pencil would become inactive/disabled when the field turns red.

Thoughts?

Thanks again for sharing this code! It's the best auto complete I've found for the Django admin. 👍 :octocat:

@mhulse mhulse changed the title X or pencil icon 404 “X” and “pencil” icon 404 Apr 12, 2015
@mlavin
Copy link
Owner

mlavin commented Apr 14, 2015

Thanks for the kind words! Just to be clear, are you are changing just the widget of a FK to use one of the autocomplete widgets to produce this behavior?

@mhulse
Copy link
Author

mhulse commented Apr 14, 2015

Hi @mlavin, thanks so much for your reply.

Thanks for the kind words!

And thanks again for this awesome bit of code! It's a life saver. I wish this functionality was built-in to Django.

With that said, I hope this isn't just an issue due to my particular project setup? I have not tested in a fresh project/app, so I apologize in advance if this issue is specific to my setup.

Just to be clear, are you are changing just the widget of a FK to use one of the autocomplete widgets to produce this behavior?

I am using it on an FK and an inline FK. I'm on Django 1.7.x and Python 3.4.x. The pencil icon is from django-admin-enhancer, but her code (I think) is what made it into the 1.8 release of Django (which now has native pencil icons, which I think are turned off by default).

My code, if it's of any help:

lookups.py

from selectable.base import ModelLookup
from selectable.registry import registry

from .models import Product, Vehicle

# https://github.com/mlavin/django-selectable/blob/master/example/core/lookups.py

class ProductLookup(ModelLookup):

    model = Product

    search_fields = (
        'engine_model__icontains',
        'vehicle__model__icontains',
        'vehicle__engine_model__icontains',
        'vehicle__manufacturer__title__icontains',
    )

registry.register(ProductLookup)

class VehicleLookup(ModelLookup):

    model = Vehicle

    search_fields = (
        'model__icontains',
        'engine_model__icontains',
        'manufacturer__title__icontains',
    )

registry.register(VehicleLookup)

forms.py

from django import forms
from django.forms.models import modelformset_factory

import selectable.forms as selectable

from .lookups import ProductLookup, VehicleLookup
from .models import Quote, Lead

SELECTABLE_ATTRS = {

    'data-selectable-options': {
        'highlightMatch': False,
    },

}

class QuoteAdminForm(forms.ModelForm):

    class Meta(object):

        model = Quote

        widgets = {
            'product': selectable.AutoCompleteSelectWidget(lookup_class=ProductLookup, attrs=SELECTABLE_ATTRS,),
        }

        fields = ('product',)

FarmFormset = modelformset_factory(Quote, QuoteAdminForm)

class LeadAdminForm(forms.ModelForm):

    class Meta(object):

        model = Lead

        widgets = {
            'vehicle': selectable.AutoCompleteSelectWidget(lookup_class=VehicleLookup, attrs=SELECTABLE_ATTRS,),
        }

        fields = ('vehicle',)

FarmFormset = modelformset_factory(Lead, LeadAdminForm)

From there, I apply the forms to my admin classes to make everything functional.

Your code works great! I just noticed if I type in a non-existent item, and the field turns red, then click the X or pencil icon I get a 404 (via the local django test server).

Again, I apologize if this is an issue that's due to my setup. I probably should have tested your code in a fresh project/app before making a comment.

Are you able to reproduce this behaviour?

Thanks for your time!

@mlavin
Copy link
Owner

mlavin commented Apr 14, 2015

Thanks for the concrete example. I'll try it out and see if I can reproduce and get a fix in place.

@mhulse
Copy link
Author

mhulse commented Apr 14, 2015

Thanks for the concrete example.

No problem at all. Sorry I forgot to provide that in my first post. 😊

I'll try it out and see if I can reproduce and get a fix in place.

Wow, that's great! Thanks so much for your time on this. Please let me know if there's anything I can do to help code-wise and/or test with. Thanks @mlavin! :octocat:

Of course, there's no pressure to find a fix. I can easily tell people to avoid typing-in bad values. I suppose another fix would be to implement the "create" functionality (my code does not allow for new objects to be created, but maybe I could turn that on?).

Thanks again! This code has been extremely useful. 👍 :octocat:

@mlavin
Copy link
Owner

mlavin commented Apr 16, 2015

I don't see this behavior in 1.8. There appears to be some difference between django-admin-enhancer and what landed. In 1.8 it is specifically looking for a select box which changes. The edit and delete links are always non-functional (and pop up dismiss is once again broken shakes fist at Django). I'll try to get this working for 1.8 and hopefully that will fix it for django-admin-enhancer as well.

@mhulse
Copy link
Author

mhulse commented Apr 17, 2015

Interesting! Thanks so much for checking. Please let me know if there is anything I can do to help.

I really appreciate your help and time. I owe you many tasty oregon micro-:beers: :octocat:! :)

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

No branches or pull requests

2 participants