Git Product home page Git Product logo

django-selectable's People

Contributors

augustomen avatar auvipy avatar bogdal avatar copelco avatar daaray avatar domdinicola avatar dpoirier avatar jab3z avatar joshaddington avatar kinfoo avatar kluchrj avatar kmtracey avatar leo-the-manic avatar manfre avatar marko90b avatar mlavin avatar morlandi avatar petrdlouhy avatar raphaelmerx avatar saex avatar slafs avatar spookylukey avatar ustun avatar vkurup avatar whiteblack avatar ykhrustalev avatar

Stargazers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

Watchers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

django-selectable's Issues

class to deal with setting a single entry to a many to many field

I had a problem getting an autocomplete input for a many to many field. (I didn't want to allow multiple selection, as the UI would have been too complicated). The problem is that the m2m manager expects to get a list, while AutoCompleteSelectField returns a single item. So here's the class I made:

#!python

class AutoCompleteSelectManyToManyField(AutoCompleteSelectField):
    def to_python(self, value):
        single_value = AutoCompleteSelectField.to_python(self, value)
        return [single_value,]

Not reading attributes properly

Maybe it's something I'm not doing right, but just followed the instructions in the docs.

When trying to hook up this in the admin. the widget wasn't picking up correctly the url to fetch data: Instead of posting to /selectable/<lookup_name>/?, it was posting to the same url of the current view. Digging a little, I notice that this line (47) in jquery.dj.selectable.js was failing to populate the attributes:

#!javascript
var data = $(input).data();

So when I added:

#!javascript
data['selectable-allow-new'] = $(input).attr('data-selectable-allow-new');
data['selectable-multiple'] = $(input).attr('data-selectable-multiple');
data['selectable-url'] = $(input).attr('data-selectable-url');
data['selectable-type'] = $(input).attr('data-selectable-type');

it worked.

I'm using the 54:18f280d4c709 revision


Adding TextareaAutocompleteWidget

Hello,
I have found I needed a variant of AutoCompleteWidget that worked as a textarea (as I needed two lines of text). I took a stab at it and here's what I have done. It's almost a copy of AutoCompleteWidget, something can probably be factored out but I am just beginning with python and this just works for me. Maybe it can be integrated in case it is useful for others.

#!python

class TextareaAutoCompleteWidget(forms.Textarea, SelectableMediaMixin):

    def __init__(self, lookup_class, *args, **kwargs):
        self.lookup_class = lookup_class
        self.allow_new = kwargs.pop('allow_new', False)
        self.qs = {}
        super(TextareaAutoCompleteWidget, self).__init__(*args, **kwargs)

    def update_query_parameters(self, qs_dict):
        self.qs.update(qs_dict)

    def build_attrs(self, extra_attrs=None, **kwargs):
        attrs = super(TextareaAutoCompleteWidget, self).build_attrs(extra_attrs, **kwargs)
        url = self.lookup_class.url()
        if self.qs:
            url = '%s?%s' % (url, urlencode(self.qs))
        attrs[u'data-selectable-url'] = url
        attrs[u'data-selectable-type'] = 'text'
        attrs[u'data-selectable-allow-new'] = str(self.allow_new).lower()
        return attrs

Problem geting app tp run

I ultimately need to use chained selection, but was trying to get things working with something simpler and tried autocompleteselect. I have a little test model class 'Cattest'. It has a field 'category', that i want to fill from the model class category. The plan being that when I render the template for 'Cattest' it would include a selectable autocompleteselectfield for the 'category' field.

I can get my form.html to load rendering the CattestForm model, but the autocompleteselectfield is not working. I am kind of new to intergrating multiple apps and using jquery, so I expect I am missing something really simple.

Your docs are much better than most, but I would like to have had a more robust example to follow. Thanks in advance for your help. I will attach a file with code snippets.


Searching model

I am trying to create a search form which searches for model records.
I want to avoid subclassing forms.ModelForm as I don't need all methods..

#!python

class SomeModel(models.Model):
    data = models.Foreignkey(Data)
    place = models.ForeignKey(Place)

There are ~1000 places so I decided to use django-selectable for Place select widget.

#!python

class SearchForm(forms.Form):
    place = selectable.AutoComboboxSelectField(
        lookup_class=PlaceLookup,
        label = _(u'Somelabel'),
        required=False,
)
    data = forms.ModelChoiceField(...)

my lookups.py

#!python

class PlaceLookup(ModelLookup):
    model = Place 
    search_fields = ('name__icontains',)

there's also a search() method in my SearchForm class which creates a django Q() instance that I use for queryset filter in my views.py (if form is valid)

The problem is that I get place_0 & place_1 in my url queryset so it's not working. The desired functionality would be &place=23 (Place.id)

What is the best way (if any) for doing such search ?

Thanks


Process result from AutoCompleteWidget

When using the AutoCompleteWidget (data comes from table through a foreign key-field) i just want to store the ID that represents what the User has chosen. I know i can "re-lookup" the string from the data-field on the form, but that makes me access the database one time too many + imagine if the result in de AutoCompleteWidget is not unique (ex. a combination FirstName + LastName), i can't re-lookup what the User has selected...)

I assume the AutoCompleteWidget is created to store the actual string of the value, but for a App with a good database structure, i work with foreign keys a lot... so the ID of the chosen record is what i'm really interested in.

Is there anything 'out of the box' for what i want to do here?

Pieter


documentation gaps

Here are two points to add to the documentation:

you must add {{ form.media.js }} and {{ form.media.css }} to the templates.

the selectable specific fields, such as AutoCompleteSelectField, take a Lookup class as a required first parameter


Simpler way to create Lookups

Hello guys, thanks for the great app! Has been helping me a lot! Here's a scenario I couldn't think of a nice solution.

Problem is the following, I've got 10 fields that I want to be autocompleted and they're all the same logic. The user just types in a string, if he clicks save and it doesn't exist, it gets created. It's pretty much like the autocomplete our browsers have.

As they all have the same logic, I have a simple model for storing the autocomplete strings. Basically it stores a key (cellphone_number, email, etc) and it's value. So if I have the fields cellphone number, email, name, etc I'd have to have one class for each of these lookups, which is not optimal. As in the future I might have more fields, I wouldn't like to have 15 classes that do the same thing and only change the "key". I'm not sure if I explained it well enough. If you guys have any doubts, please ask!

It'd be sweet if I could create a new base class for these kinds of lookups and then I could just instantiate with the key. Something in the lines of:

#!python

email = forms.CharField( widget=selectable.AutoCompleteWidget(MySweetCustomLookup(key="email"))

Any idea if this is possible? MANY THANKS IN ADVANCE!


Allow select widgets to work alone

Currently AutoCompleteSelectWidget and AutoComboboxSelectWidget do not play nice with other fields (like ModelChoiceField) because they return a list [text, pk] rather than just the pk. Part of this is because of the ability to add new items which is handled by the field. Perhaps support for adding items could be dropped if something along the lines of #30 was implemented.


Field label from model

I am sorry if this has already been applied by I am trying to use AutoComboboxSelectField in my django forms.ModelForm

If I choose to only change the widget, 2 values are being posted to the server (probably because of __unicode__representation).

Problem disappears If I override the field instead of widget but I can't get the field label from models it selects..

Is there any way so I can get the label from models.py of the specified form field ?

Thanks


Only query if user is logged

Hello,

I've searched the issues and the docs and found no documentation about selectable only working if the user is logged in. I would like to suggest a new parameter must_be_authenticated (default: false)?

Here's how I've done it so far, would this be the recommended path or is there an easier way to protect a particular lookup?

#!python

    def results(self, request):
        if self.must_be_authenticated and request.user.is_authenticated():
            return super(ModelLookup, self).results(request)
        else:
            return HttpResponseForbidden()

Update not working

When modifying an entry using AutoComboboxSelectField, I am unable to update this entry, except when I loose focus from the select field by clicking somewhere else on the page before submitting the form.

I am no JavaScript guru, so I don't know where to look at the js code to solve the issue, but it seems that there should be somewhere an update of the form values after choosing a new value.


Pressing enter when autocomplete input box is blank will delete first item

Having an issue when using django-selectable for manytomany field in Django admin.

When I go to the a selectable-controlled input box, it is initially blank. If I focus on the box and press enter, the first manytomany item that's already been added previously gets deleted. If I then save the item is lost for good!


Make it work with dynamically added forms

The problem is: when using the autocomplete fields in formsets that can add forms dynamically (with javascript), like admin inlines, the autocomplete widget is not initialized for newly created widgets.

Dynamic formsets works by keeping a hidden form that gets cloned when the user clicks the "Add" button/link. That hidden form has the widget correctly initialized, but it isn't mean to be used for interaction, only for cloning, to create new forms. When the form gets cloned, the new cloned one doesn't respond to keystrokes, and it may have the events attached, but still related to the hidden widget. Also, calling bindSelectables() after the form has been cloned does nothing.


Investigate Twitter Bootstrap Compatibility

There was a question about if django-selectable could be used with Twitter Bootstrap and for now it appears the answer is no. The autocomplete plugin in Bootstrap (called typeahead) does not currently support remote sources. There are a couple open issues/examples for adding this:

However Bootstrap is gaining a lot of popularity and having selectable work along side it would be great. Some options are:

Point people to jQuery UI bootstrap theme: http://addyosmani.github.com/jquery-ui-bootstrap

Wait until typeahead adds remote sources

Add support for remote typeahead in django-selectable


Dynamically added forms

The issue is similar to <<issue 12>>, an autocomplete form is not working with dynamically added fields. I'm using django-dynamic-formsets and passing the bindSelectables() to the added option, but only the first field is working as expected, also removing fields broke the functionality of the form


Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.