-
Notifications
You must be signed in to change notification settings - Fork 317
more structured quick start #542
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
Changes from 9 commits
acef399
79c301e
d77d0b3
d1e9df5
71ff4df
695c985
05616af
75fc6cd
70ca7b2
b618ee9
ca57ebf
2984192
945b3f5
25197fc
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -1,3 +1,4 @@ | ||
| *~ | ||
| *.pyc | ||
|
|
||
| Django_Select2.egg-info | ||
|
|
||
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,15 @@ | ||
| Hints to Developers | ||
|
||
| ========================= | ||
|
|
||
| Documentation pull requests welcome. | ||
|
|
||
| Please do not add the "missing" Makefile. That is intentionally so. | ||
| Compile the docs locally by ways of ``python setup.py build_sphinx``. | ||
|
|
||
| Bug reports welcome, even more so if they include a correct patch. Much | ||
| more so if you start your patch by adding a failing unit test, and correct | ||
| the code until zero unit tests fail. | ||
|
|
||
| Please note: the test suite uses the newly introduced f-strings, so that it | ||
| needs Python3.6+ to run. The code itself is targeted at Python3.5+. | ||
|
|
||
| Original file line number | Diff line number | Diff line change | ||||
|---|---|---|---|---|---|---|
|
|
@@ -49,8 +49,9 @@ DjangoSelect2 handles the initialization of select2 fields automatically. Just i | |||||
| ``{{ form.media.js }}`` in your template before the closing ``body`` tag. That's it! | ||||||
|
|
||||||
| If you insert forms after page load or if you want to handle the initialization | ||||||
| yourself, DjangoSelect2 provides a jQuery plugin. It will handle both normal and | ||||||
| heavy fields. Simply call ``djangoSelect2(options)`` on your select fields.:: | ||||||
| yourself, DjangoSelect2 provides a jQuery plugin, replacing and enhancing the Select2 | ||||||
| plugin. It will handle both normal and heavy fields. Simply call | ||||||
| ``djangoSelect2(options)`` on your select fields.:: | ||||||
|
|
||||||
| $('.django-select2').djangoSelect2(); | ||||||
|
|
||||||
|
|
@@ -59,6 +60,9 @@ You can pass see `Select2 options <https://select2.github.io/options.html>`_ if | |||||
|
|
||||||
| $('.django-select2').djangoSelect2({placeholder: 'Select an option'}); | ||||||
|
|
||||||
| Please replace all your ``.select2`` invocations with the here provided | ||||||
|
Collaborator
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more.
Suggested change
|
||||||
| ``.djangoSelect2``. | ||||||
|
|
||||||
| Security & Authentication | ||||||
| ------------------------- | ||||||
|
|
||||||
|
|
||||||
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -8,6 +8,17 @@ Overview | |
| .. automodule:: django_select2 | ||
| :members: | ||
|
|
||
| Assumptions | ||
| ----------- | ||
|
|
||
| * You have a Django project, possibly with models linked by foreign key fields, | ||
|
||
| * are using Python3, | ||
| * set up a virtual environment with ``python3 -m venv <location>``, | ||
| * activated the virtual environment, | ||
| * installed ``django`` using ``pip``, | ||
|
||
| * are already using Django forms, | ||
| * and your select lists are too long, or they look ugly to you. | ||
|
|
||
| Installation | ||
| ------------ | ||
|
|
||
|
|
@@ -17,11 +28,12 @@ Installation | |
|
|
||
| 2. Add ``django_select2`` to your ``INSTALLED_APPS`` in your project settings. | ||
|
|
||
| 3. Add ``django_select`` to your ``urlconf``:: | ||
|
|
||
| 3. Add ``django_select`` to your ``urlconf`` **if** you use any | ||
| :class:`ModelWidgets <.django_select2.forms.ModelSelect2Mixin>`:: | ||
| path('select2/', include('django_select2.urls')), | ||
|
|
||
| url(r'^select2/', include('django_select2.urls')), | ||
| You can safely skip this one if you do not use any | ||
| :class:`ModelWidgets <.django_select2.forms.ModelSelect2Mixin>` | ||
|
|
||
| Quick Start | ||
| ----------- | ||
|
|
@@ -30,19 +42,22 @@ Here is a quick example to get you started: | |
|
|
||
| 0. Follow the installation instructions above. | ||
|
|
||
| 1. Add a select2 widget to the form. For example if you wanted Select2 with multi-select you would use | ||
| ``Select2MultipleWidget`` | ||
| Replacing:: | ||
| 1. Replace native Django forms widgets with one of the several ``django_select2.form`` widgets. | ||
| Start by importing them into your forms.py, right next to django own ones:: | ||
mfrasca marked this conversation as resolved.
Outdated
Show resolved
Hide resolved
|
||
|
|
||
| class MyForm(forms.Form): | ||
| things = ModelMultipleChoiceField(queryset=Thing.objects.all()) | ||
| from django import forms | ||
| from django_select2 import forms as s2forms | ||
|
Collaborator
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Good call to include the imports. I always forget 👍 |
||
|
|
||
| with:: | ||
| Then let's assume you have a model with a Choice, a ForeignKey, and a | ||
mfrasca marked this conversation as resolved.
Outdated
Show resolved
Hide resolved
|
||
| ManyToMany field, you would add this information to your Form Meta | ||
mfrasca marked this conversation as resolved.
Outdated
Show resolved
Hide resolved
|
||
| class:: | ||
|
|
||
| from django_select2.forms import Select2MultipleWidget | ||
|
|
||
| class MyForm(forms.Form): | ||
| things = ModelMultipleChoiceField(queryset=Thing.objects.all(), widget=Select2MultipleWidget) | ||
| widgets = { | ||
|
Collaborator
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Please include the entire code example, otherwise people will be confused.
Contributor
Author
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. I haven't written it yet. I'll review the PR in its entirety, and come back to you soon (36h).
Contributor
Author
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. 36h went by, and I'm still busy on the project I'm working at. (mfrasca/ghini) |
||
| 'category': s2forms.Select2Widget, | ||
| 'author': s2forms.ModelSelect2Widget(model=auth.get_user_model(), | ||
|
Collaborator
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. You did not import |
||
| search_fields=['first_name__istartswith', 'last_name__icontains']), | ||
| 'attending': s2forms.ModelSelect2MultipleWidget … | ||
| } | ||
|
|
||
| 2. Add the CSS to the ``head`` of your Django template:: | ||
|
|
||
|
|
||
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -15,6 +15,7 @@ Contents: | |
| get_started | ||
| django_select2 | ||
| extra | ||
| developers | ||
|
|
||
| Indices and tables | ||
| ================== | ||
|
|
||
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I'm a
emacsuser, I put this one everywhere.There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Ok, I prefer to only have language or build specific things the
.gitignorefile. If you have things that are specific to your local environment, please put them into your global gitignore.There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
did not know of this option. thank you, it's useful.