Git Product home page Git Product logo

Comments (1)

applegrew avatar applegrew commented on August 17, 2024

Its been a long time since I worked on this project so I may not remember very accurately. Please take my suggestions with a pinch of salt.

Do I need to create a view for each of my ajax lookups? The blog it implies that I need to, but it makes no mention of a corresponding url to go with it. I'm assuming I need one so created one. My confusion is around the url(r"^select2/", include("django_select2.urls")), paragraph and what exactly it does?

It depends. For the fields with Auto prefix the library automatically associates them with a view. This is one central view which serves all Ajax queries by all Auto fields. More accurately this central view routes those queries to your field instance. For this central view to be accessible we need to include the url(r"^select2/", include("django_select2.urls")) in your urls file. Before using Auto fields read the caveats here - http://django-select2.readthedocs.org/en/latest/get_started.html#module-django_select2

Once the view is created it's unclear how I tie this view to the form? I made the assumption based on the testapp that I need to use the HeavySelect2ChoiceField with a data_view as an argument. Is this correct?

Yes you are correct, but make sure the view name that you specify can be resolved by reverse().

How do I apply the basic allowClear: true to this example? This doesn't work?

Yes that is the way to apply Select2 settings, but you need not and should not set allowClear option. That is overridden by this library since that needs to be in-sync with the internal state. For example in this case you did not set required=False so this field is a mandatory, since all Django fields have required set to true by default (ref). So, this library sets allowClear to false irrespective of what you had set, so that users have a visual clue that empty value is not valid.

Is this implementation how you currently would like this to be done? I say this b/c it looks like the test app and the blog differ in the process?

Well the blog, code and the docs are in sync, but I may not have been very clear.

Are there ways to optimize my implementation? Clearly if you aren't using a customized queryset you can use your AutoModelSelect2Field but this has some drawbacks as you still need to implement security_check and get_results unless you want them all?

I am not sure what you mean. AutoModelSelect2Field takes care of all the details. You need not implement security_check or get_results. See the testapp for examples.

Why did you choose not to use the standard get_queryset as a method to feeding get_results and using (object.id, object.unicode()) followed by filtering object.unicode for the term?

Again I am not sure what you mean.

As far as I can see your reference implementation, in your mixin you are trying to to very much the thing which is already done for you. Below the few lines will do what your mixin is trying to do.

class CityChoices(AutoModelSelect2Field):
    queryset = City.objects
    search_fields = ['name__icontains', 'county__name__icontains', 'county__state__icontains', ]

from django-select2.

Related Issues (20)

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.