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

Issue with Ajax-Search on Media-Fields #60

Closed
nfoonf opened this issue Dec 10, 2013 · 4 comments
Closed

Issue with Ajax-Search on Media-Fields #60

nfoonf opened this issue Dec 10, 2013 · 4 comments

Comments

@nfoonf
Copy link

nfoonf commented Dec 10, 2013

Hi,
I've got an Issue if I try to use django-ajax-selects on a media-field.
Django breaks with following stack-trace:

File "/home/vagrant/edn-venv/local/lib/python2.7/site-packages/django/utils/decorators.py" in _wrapped_view
  91.                     response = view_func(request, *args, **kwargs)
File "/home/vagrant/edn-venv/local/lib/python2.7/site-packages/django/utils/decorators.py" in bound_func
  21.                 return func(self, *args2, **kwargs2)
File "/home/vagrant/edn-venv/local/lib/python2.7/site-packages/django/db/transaction.py" in inner
  223.                 return func(*args, **kwargs)
File "/home/vagrant/edn-venv/local/lib/python2.7/site-packages/django/contrib/admin/options.py" in change_view
  1127.         media = self.media + adminForm.media
File "/home/vagrant/edn-venv/local/lib/python2.7/site-packages/django/contrib/admin/helpers.py" in _media
  66.             media = media + fs.media

Exception Type: TypeError at /admin/edn_server/location/199737/
Exception Value: unsupported operand type(s) for +: 'AutoCompleteSelectMultipleField' and 'Media'

I found a fix for this issue in the old Bugtracking on google code( https://code.google.com/p/django-ajax-selects/issues/detail?id=80) , but though it works I am not totally happy with it and still do not thoroughly understand the underlying problem.
Also I would not be surprised, if this issue is in my code and I'm kind of 'holding it wrong' :-(

cheers,
nfoonf

@crucialfelix
Copy link
Owner

which django are you using ?
what do you mean by media-field ? is this a form that has media in its Meta class ?
post the code where you use the form or field.
thanks !

@nfoonf
Copy link
Author

nfoonf commented Dec 10, 2013

Hi,

thanks for the quick reply, and I apologize for not providing more details.

I use Django 1.5.5

I am using it inside the admin.py only at the moment. So I do not create any forms but built it likewise your example:

class Admin(AjaxSelectAdmin):
    filter_horizontal = ('region', )
    search_fields = ['title', 'id']
    list_filter = ('status',)
    list_display = ('title', 'get_status')

    form = make_ajax_form(
        models.Event,
        {
            "recurring_location": 'location',
            'parent': 'event',
            'region': 'region',
            'media': 'media'
        }
    )

code in settings.py and lookups.py is also basically similar to your example, it works for all other lookup channels but for the one called 'media'. I also tried renaming it, but it that changed nothing. :-(

AJAX_LOOKUP_CHANNELS = {
    'county'     : ('edn_server.lookups', 'CountyLookup'),
    'district'     : ('edn_server.lookups', 'DistrictLookup'),
    'region'     : ('edn_server.lookups', 'RegionLookup'),
    'media'     : ('server.lookups', 'MediaLookup'),
}


class MediaLookup(LookupChannel)

    def get_query(self, q, request):
        return self.model.Media.objects.filter(title__icontains=q).order_by('title')

@nfoonf
Copy link
Author

nfoonf commented Dec 10, 2013

Hi,

I found something out:

It works for model_fieldnames that are not called 'media'.

This Admin works without a problem after I Disable the 'media'-field in the Admin View:

class LocationAdmin( AjaxSelectAdmin):
    filter_horizontal = ('edn_category', 'category', 'region')
    search_fields = ['title', 'id']
    list_filter = ('status',)
    list_display = ('title', 'get_status')
    raw_id_fields = ('parent',)
    form = make_ajax_form(
        models.Location,
        {
            'city': 'city',
            'parent': 'location',
            #'media': 'media',
            'logo': 'media',
            'topfoto': 'media'
        }
    )

Update:
Okay, I actually found the bug:
As I found out it is not really a good Idea to name an object field 'media' as we overwrite the 'media'-Property object with it.:-(

@crucialfelix
Copy link
Owner

As per your pull request I disabled the setting for attributes on the form field. Normal usage of form fields does not depend on that. There is a chance that this breaks somebody's code, but that would be only because they were rendering the form themselves and referring to fields by form.fieldname

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

2 participants