Comments (10)
@artscoop What problems/errors did this cause? I didn't see any errors caused by this problem with my project, so just wondering what is different. I don't use make_ajax_form, not convinced that would cause the problem however.
from django-ajax-selects.
In Django 1.7 release notes, I see "It is now possible to pass a callable as value for the attribute limit_choices_to when defining a ForeignKey or ManyToManyField". I can't see this causing the problems described though.
from django-ajax-selects.
I've just has the problem again (and forgot I already filed an issue) I use make_ajax_form in the admin.
Django 1.7 admin interface introduced code using limit_choices_to
on form fields. However AutoCompleteSelectField
s don't have this attribute set. Hence the program failing.
from django-ajax-selects.
if you have a chance to submit a pull request then the fix can be published
fairly quickly
On Mon, Nov 10, 2014 at 3:20 PM, artscoop [email protected] wrote:
I've just has the problem again (and forgot I already filed an issue) I
use make_ajax_form in the admin.
Django 1.7 admin interface introduced code using limit_choices_to on form
fields. However AutoCompleteSelectFields don't have this attribute set.
Hence the program failing.—
Reply to this email directly or view it on GitHub
#83 (comment)
.
from django-ajax-selects.
AutoCompleteSelectFields inherits from forms.fields.CharField. It doesn't look like CharField defines or uses a limit_choices_to field.
Hence, I am still a bit confused what this limit_choices_to attribute is or why it is needed.
The best I can come up with is that Django admin is doing something dodgy.
Would be interested to see a full stack trace of the error. The only code I can see doesn't appear to be applicable (BaseModelForm init function) because AutoCompleteSelectFields doesn't define a queryset attribute.
from django-ajax-selects.
I glanced at the docs today. limit_choices_to sounds like it is optional.
the default is to not limit the choices at all -- query.set.all()
I'm surprised that they would introduce a breaking change like that, but
its entirely possible.
if I had time I would set up unit testing with travis so we would see all
the versions with the errors.
the example app is pretty easy to start up using any django version for
quick manual testing.
On Mon, Nov 10, 2014 at 11:21 PM, Brian May [email protected]
wrote:
AutoCompleteSelectFields inherits from forms.fields.CharField. It doesn't
look like CharField defines or uses a limit_choices_to field.Hence, I am still a bit confused what this limit_choices_to attribute is
or why it is needed.The best I can come up with is that Django admin is doing something dodgy.
Would be interested to see a full stack trace of the error. The only code
I can see doesn't appear to be applicable (BaseModelForm init function)
because AutoCompleteSelectFields doesn't define a queryset attribute.—
Reply to this email directly or view it on GitHub
#83 (comment)
.
from django-ajax-selects.
I am starting to suspect it might actually be a Django bug. i.e. they broke something without intending to. As such it may deserve a Django bug report at https://code.djangoproject.com/query.
from django-ajax-selects.
This is the code breaking with AutoCompleteSelectField
(django/forms/models.py, 333, in BaseModelForm.__init__
):
# Apply ``limit_choices_to`` to each field.
for field_name in self.fields:
formfield = self.fields[field_name]
if hasattr(formfield, 'queryset'):
limit_choices_to = formfield.limit_choices_to
if limit_choices_to is not None:
if callable(limit_choices_to):
limit_choices_to = limit_choices_to()
formfield.queryset = formfield.queryset.complex_filter(limit_choices_to)
I've found it breaks only with one of my LookupChannel
s:
class PictureLookup(LookupChannel):
model = Picture
plugin_options = {'minLength': 2, 'delay': 500}
def get_query(self, q, request):
fields = ['title', 'description', 'image']
final_query = search_query(q, fields)
return Picture.objects.filter(final_query).order_by('-id')
def get_result(self, obj):
return obj.__unicode__()
def format_match(self, obj):
output = u"{thumb} {name}".format(thumb=obj.get_thumbnail_html(size=(48,20), template='picture'), name=obj.title or obj.description)
return output
def format_item_display(self, obj):
output = u"<div>{thumb} {name}</div>".format(thumb=obj.get_thumbnail_html(size=(48,20)), name=obj.title or obj.description)
return output
but it works like a charm with this LookupChannel
:
class CityPublicMinimalLookup(CityLookup):
model = City
min_length = 4
plugin_options = {'minLength': 4, 'delay': 0, 'position': {"my": "left bottom", "at": "left top", "collision": "flip"}}
def get_query(self, q, request):
fields = ['alternates__ascii']
final_query = search_query(unidecode(q).strip(), fields)
final_query = models.Q(city=True, country__public=True) & final_query
items = City.objects.filter(final_query).distinct().order_by('-population')[0:10]
return items
def format_item_display(self,obj):
output = u"""{country} <span class="text-muted">{code}</span> {name}""".format(name=obj.get_name(), country=obj.get_country_icon(directory="png"), code=obj.get_code())
return output
from django-ajax-selects.
Wow. Finally nailed it. In my admin definition I added a queryset to a ForeignKey
def get_form(self, request, obj=None, **kwargs):
form = super(ProfileAdmin, self).get_form(request, obj, **kwargs)
if obj is not None:
form.base_fields['picture'].queryset = obj.pictures.all()
return form
I can't tell why it's mandatory for a FormField
with a queryset
to also have a limit_choices_to
attribute. I'm going to file a Django ticket to know if that's a bug.
from django-ajax-selects.
yeah, that looks like a minor django bug. probably unintentional. it gets
quite hairy in the forms and admins and everybody is working with this
limited api.
for instance you cannot easily get the request and user when you are
filtering that query set. I had to make a custom admin that allows the
field to filter_by_request. for instance only show checkboxes for the
user's own items.
On Tue, Nov 11, 2014 at 3:52 AM, artscoop [email protected] wrote:
Wow. Finally nailed it. In my admin definition I added a queryset to a
ForeignKeydef get_form(self, request, obj=None, *_kwargs):
form = super(ProfileAdmin, self).get_form(request, obj, *_kwargs)
if obj is not None:
form.base_fields['picture'].queryset = obj.pictures.all()
return formI can't tell why it's mandatory for a FormField with a queryset to also
have a limit_choices_to attribute. I'm going to file a Django ticket to
know if that's a bug.—
Reply to this email directly or view it on GitHub
#83 (comment)
.
from django-ajax-selects.
Related Issues (20)
- Should +add popup work in the view outside of Admin? HOT 2
- Warning a parser-blocking crose site script HOT 4
- How to customize Widger from textbox to dropdownlist HOT 3
- Problems to implement add button outside the admin HOT 3
- Autocomplete using `inlineformset_factory`
- Documentation & example code using different urls.py HOT 1
- Issue with wagtail fields after updating from 1.7 => 1.8 HOT 2
- Django-ajax-selects and Django Rest Framework HOT 1
- Not sure what Tag is. HOT 1
- bug? add new item, initialize inline item with django-nested-admin HOT 4
- AutoCompleteSelectMultiple add new stopped to work with Django 4.1 HOT 6
- In Django 4.2 admin the search-field is displayed wrong (too large and beside item-list) HOT 3
- Admin in dark mode = trash/delete/remove icon invisible HOT 6
- How add to ajax request additional GET params? HOT 2
- Update documentation for Django 4.2
- the 3.0.0 release broke 2.2.0 for older python HOT 13
- v3.0.0 AutoCompleteSelectMultiple Add New not working with Django 4.2.8 nor 5.0.0 HOT 6
- extra_attrs tag deformed in templates
- Django add new popup window not working if nested HOT 1
- `collectstatic` doesn't work properly with new version of `jquery-ui`
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-ajax-selects.