theatlantic / django-select2-forms Goto Github PK
View Code? Open in Web Editor NEWDjango form fields using the Select2 jQuery plugin
License: Other
Django form fields using the Select2 jQuery plugin
License: Other
The code currently sets meta.auto_created
for the SortableThroughModelBase
class.
Unfortunately, this means that in our app, when we have a model inheriting from SortableThroughModel
, then Django's makemigrations
will ignore that model, and we won't get the tables automatically created.
Worse, if we manually create the migration for this model, then a future makemigrations
will try to delete it.
Unless we missed something, this means we completely lose the benefits of makemigrations
, and if we start using SortableThroughModelBase
then we can't rely on makemigrations
any more.
Why is auto_created
set this way? Is there any way to not have it set, so that makemigrations
works?
Or should we be doing things differently?
Not work with Django 3.
ImportError: cannot import name 'six' from 'django.utils
pypi has 2.0.1 but there's 2.0.2 in github. Could you please upgrade pypi release?
Not working in template forms only admin.
We had a project on Python 3.9 and the minute I started using PDM I got this warning, for some reason PDM has revealed the warning:
select2/views.py:107: SyntaxWarning: "is" with a literal. Did you mean "=="?
You shouldn't be using is
to check for equality, is
is for checking identity only for things like if something is None
Did you want me to send a quick patch?
If you click "Add Another" to add another form and then try to use the select2 widget in that form, it doesn't work properly. The dropdown shows up at the top of the screen and as far as I can tell it's not functional. I'm happy to look into this further if you can point me in the right direction.
Why the city field is hidden? I render the form via {{ form.as_p }}
<input type="hidden" name="city" data-placeholder="None" class="django-select2" data-sortable="false" id="id_city" data-select2-options="{"ajax": {"url": "/select2/fetch_items/users/user/city/", "dataType": "json", "quietMillis": 200}, "allowClear": true}" data-init-selection-url="/select2/init_selection/users/user/city/" />
city = select2.fields.ForeignKey(City, blank=True, null=True, ajax=True, search_field='name', js_options={'quiet_millis': 200}, on_delete=models.PROTECT)
subject
I'm not super proficient at JavaScript, but from what I can tell, any page on which I load the select2.jquery_ready.js file, the '$' jquery object becomes undefined. I've validated this with code elsewhere on the page, removing all other scripts, and trying to access '$' via the console. Also, when reassigning the variable just after loading the script with 'var $ = jQuery', everything works as expected. I can't tell which part of the file might be causing this.
I'm using your wonderful library for a simple ChoiceField. However, using it in this way:
from select2.fields import ChoiceField
class MyForm(forms.Form):
something = ChoiceField(choices=('what', 'ever'))
will result in an exception in line 115 of widgets.py when rendering the widget in a template.
There are two problems with that line:
I'll prepare some edits that should resolve the problem. However, since I'm only using and testing the changes with a simple ChoiceField, don't trust them too far.
File "/home/user/site/app/models.py", line 14, in <module>
import select2.fields
File "/opt/py27/lib/site-packages/select2/fields.py", line 10, in <module>
from .models.descriptors import SortableReverseManyRelatedObjectsDescriptor
File "/opt/py27/lib/site-packages/select2/models/descriptors.py", line 4, in <module>
from django.db.models.fields.related import ReverseManyRelatedObjectsDescriptor
ImportError: cannot import name ReverseManyRelatedObjectsDescriptor
One of the projects that I'm working on is running into an issue with the unicode calls in views.py. These were fixed 3 months ago on master and the 2.1.0 release seems to contain these fixes.
However, pypi only has version 2.0.2 listed so I can't install 2.1.0 with pip. Is there a timeline for when 2.1.0 will be pushed to pypi?
We're in the process of finalizing the 4.0 release and are aiming to have it done by the end of this month at the latest.
Since I'm not very familiar with this plugin, I can't really judge how easy it is going to be to migrate over to the new version.
Django throws "DeprecationWarning: django.conf.urls.defaults is deprecated; use django.conf.urls instead"
https://docs.djangoproject.com/en/dev/releases/1.5/#system-version-of-simplejson-no-longer-used
Since Django 1.5 drops support for Python 2.5, we can now rely on the json module being available in Python’s standard library, so we’ve removed our own copy of simplejson. You should now import json instead of django.utils.simplejson.
This breaks views.py
(django: 1.8.9, django-select2-forms: HEAD)
The event is binded to the hidden form that is used to instanciate the new form when the user click on the "Add another". When a new form is instanciated its id is dynamically changed.
When the event is trigger it still target the hidden form and not the new one. You can see that the options are added to the hidden form rather than the new one.
Make sure that the events are not binded to the hidden form
Dynamically bind the field on the dynamic form. This should be easier with the new`formset:addedand
formset:removed`` jQuery events in Django 1.9 django/django@1335aa2
related_name=_('name')
related.py", line 1782, in contribute_to_related_class
setattr(cls, related.get_accessor_name(), self.related_accessor_class(relat
d))
UnicodeEncodeError: 'ascii' codec can't encode characters in position 0-4: ordi
al not in range(128)
Django 1.9.7, Python 3.4, Ubuntu (Vagrant)
Hi there,
sorry for opening an issue for this. I couldn't find any info on this topic in the documentation, can you point me in the right direction? Or is it not a possibility as of now to limit the available choices based on the current user?
Thanks!
I noticed this in select2/Select2View.py
try:
page = int(page)
except TypeError:
raise InvalidParameter("Invalid page '%s' passed")
else:
if page < 1:
raise InvalidParameter("Invalid page '%s' passed")
The value of page
needs to be interpolated into both exception messages.
In [1]: import select2
In [2]: select2.fields
---------------------------------------------------------------------------
AttributeError Traceback (most recent call last)
<ipython-input-2-6ec2b8b5794a> in <module>()
----> 1 select2.fields
AttributeError: 'module' object has no attribute 'fields'
In [3]: dir(select2)
Out[3]:
['__builtins__',
'__doc__',
'__file__',
'__name__',
'__package__',
'__path__',
'__version__',
'__version_info__']
In [4]: import select2.fields
In [5]: dir(select2)
Out[5]:
['__builtins__',
'__doc__',
'__file__',
'__name__',
'__package__',
'__path__',
'__version__',
'__version_info__',
'fields',
'models',
'utils',
'widgets']
PyPi has an older version of the library which can't be used with Django 1.9.
The MultipleSelect still shows
Hold down "Control", or "Command" on a Mac, to select more than one.
help_text. It doesn't hurt holding down Control, but it isn't really needed if Select2 kicks in.
I use modernizr, so putting the "Hold down Control" message in a span with a class of "controlmsg" would be great. Then I can hide it with
.js .controlmsg {
display: none;
}
and still have it gracefully there when javascript is disabled.
Any better idea for the controlmsg classname? Or another solution for the issue? Perhaps <noscript>
tags are still allowed?
I'm using Django 1.11 and the select2 form autosuggests and completes perfectly in admin, but on my HTML page it doesn't.
In HTML, my form field is called tags and I'm using
{{forms.media}}
{{forms.tags}}
forms.py
...
tags = select2.fields.MultipleChoiceField(Tag,overlay="Choose several skills...")
...
models.py
...
tags = select2.fields.ManyToManyField(Tag,overlay="Choose several skills...",ajax=True,search_field="name")
...
I like how you don't render <script>
in the widget (which is what django-select2 does) as it enables me to put all javascript at the end of the document, using {{form.media.js}} and css in the head using {{form.media.css}}
This should be documented somewhere.
Hi,
I have installed the django-select2-forms in my django project and I have problem to create model
EntryAuthors, I have been developing my application in django 1.8.2. My problem comes with m2m field where I need to have ability to store order of elements. When I set models: Author and Entry from first example it works fine, but when I try to add middle table EntryAuthors I can't create migration for this table and migrate it. My problem comes with EntryAuthors(select2.models.SortableThroughModel) code in bracket. Can you check this issue, or create simple project for example m2m with storing order with your modul in django 1.8 and put somewhere?
I have a error in the moment: import select2.fields
File "C:\Python34\lib\site-packages\select2\fields.py", line 7, in
from django.utils.encoding import force_unicode
ImportError: cannot import name 'force_unicode'
A declarative, efficient, and flexible JavaScript library for building user interfaces.
🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.
TypeScript is a superset of JavaScript that compiles to clean JavaScript output.
An Open Source Machine Learning Framework for Everyone
The Web framework for perfectionists with deadlines.
A PHP framework for web artisans
Bring data to life with SVG, Canvas and HTML. 📊📈🎉
JavaScript (JS) is a lightweight interpreted programming language with first-class functions.
Some thing interesting about web. New door for the world.
A server is a program made to process requests and deliver data to clients.
Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.
Some thing interesting about visualization, use data art
Some thing interesting about game, make everyone happy.
We are working to build community through open source technology. NB: members must have two-factor auth.
Open source projects and samples from Microsoft.
Google ❤️ Open Source for everyone.
Alibaba Open Source for everyone
Data-Driven Documents codes.
China tencent open source team.