Comments (1)
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)
- Option to choose search_fields for Select2MultipleWidget ? HOT 2
- support django3.0 HOT 2
- DjangoCMS 3.7 HOT 8
- Clean option no works properly HOT 2
- Issues when certain special characters appear in the field_id HOT 5
- How to add limitations to a RelatedFieldMixin HOT 1
- js config file HOT 3
- multi model select field HOT 1
- Release 7.2.1 on PIP HOT 6
- Interdependent selects for fields of one model HOT 3
- ModelSelect2Widget initial value is not selected HOT 6
- How do I load selected options for ModelSelect2MultipleWidget HOT 5
- Disable multiple select on tag widget HOT 5
- ModelSelect2TagWidget tagging new values HOT 9
- Implementation of Select2Widget with formsets. HOT 6
- Use https://<cdn>/ rather than //<cdn>/ for security? HOT 4
- Codecov migration to marketplace app HOT 2
- Django Select2 not working for formset when click on add more. HOT 1
- Django ModelSelect2MultipleWidget for ManyToMany field not working HOT 5
- Empty Dropdown Using ModelSelect2Widget HOT 2
Recommend Projects
-
React
A declarative, efficient, and flexible JavaScript library for building user interfaces.
-
Vue.js
🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.
-
Typescript
TypeScript is a superset of JavaScript that compiles to clean JavaScript output.
-
TensorFlow
An Open Source Machine Learning Framework for Everyone
-
Django
The Web framework for perfectionists with deadlines.
-
Laravel
A PHP framework for web artisans
-
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.
-
Visualization
Some thing interesting about visualization, use data art
-
Game
Some thing interesting about game, make everyone happy.
Recommend Org
-
Facebook
We are working to build community through open source technology. NB: members must have two-factor auth.
-
Microsoft
Open source projects and samples from Microsoft.
-
Google
Google ❤️ Open Source for everyone.
-
Alibaba
Alibaba Open Source for everyone
-
D3
Data-Driven Documents codes.
-
Tencent
China tencent open source team.
from django-select2.