Open ibnubay opened 7 years ago
Could you try with --traceback
and paste the traceback here ?
Thanks
here... the traceback
Internal Server Error: /tms/users/list_user/
Traceback (most recent call last):
File "/Users/1bn4y/miniconda3/envs/ralali/lib/python2.7/site-packages/django/core/handlers/base.py", line 149, in get_response
response = self.process_exception_by_middleware(e, request)
File "/Users/1bn4y/miniconda3/envs/ralali/lib/python2.7/site-packages/channels/handler.py", line 227, in process_exception_by_middleware
return super(AsgiHandler, self).process_exception_by_middleware(exception, request)
File "/Users/1bn4y/miniconda3/envs/ralali/lib/python2.7/site-packages/django/core/handlers/base.py", line 147, in get_response
response = wrapped_callback(request, *callback_args, **callback_kwargs)
File "/Users/1bn4y/miniconda3/envs/ralali/lib/python2.7/site-packages/django/views/generic/base.py", line 68, in view
return self.dispatch(request, *args, **kwargs)
File "/Users/1bn4y/miniconda3/envs/ralali/lib/python2.7/site-packages/dal/views.py", line 32, in dispatch
return super(ViewMixin, self).dispatch(request, *args, **kwargs)
File "/Users/1bn4y/miniconda3/envs/ralali/lib/python2.7/site-packages/django/views/generic/base.py", line 88, in dispatch
return handler(request, *args, **kwargs)
File "/Users/1bn4y/miniconda3/envs/ralali/lib/python2.7/site-packages/django/views/generic/list.py", line 159, in get
self.object_list = self.get_queryset()
File "/Users/1bn4y/Projects/ralali/gitlab/seal-trax-web/src/user_management/users/views.py", line 49, in get_queryset
qs = super(UserCombo, self).get_queryset()
File "/Users/1bn4y/miniconda3/envs/ralali/lib/python2.7/site-packages/dal/views.py", line 66, in get_queryset
qs = super(BaseQuerySetView, self).get_queryset()
File "/Users/1bn4y/miniconda3/envs/ralali/lib/python2.7/site-packages/django/views/generic/list.py", line 44, in get_queryset
'cls': self.__class__.__name__
ImproperlyConfigured: UserCombo is missing a QuerySet. Define UserCombo.model, UserCombo.queryset, or override UserCombo.get_queryset().
So in my opinion with dal is:
ModelForms set queryset from __init__
then send to autocomplete.Select2QuerySetView via autocomplete.ModelSelect2...
Is it possible?
Thanks
It seems like you have two questions which I understand.
The first is , why do you have this traceback. I don't know, if you can reproduce it in the test_project then I could debug it.
The second is, is there a way to define the queryset OAOO ? Yes, you can make a function that returns the queryset and call it in both the view and the widget.
Hi @jpic, My last development is using django-select2, but it sometimes auto.json is broken.
in my forms.py is:
class CompanyWidget(ModelSelect2Widget):
model = CompanyProfile
search_fields = [
'name__icontains',
]
class CompanyProfileForm(forms.ModelForm):
class Meta:
model = CompanyProfile
fields = (
'comp_name', 'comp_address', 'comp_phone', 'comp_fax', 'comp_web', 'comp_fleet', 'comp_logo', 'comp_pic')
widgets = {
'comp_pic': CompanyWidget(attrs={'data-placeholder': 'Select User Pic', 'data-theme': 'bootstrap',
'data-allow-clear': 'true'}),
def __init__(self, *args, **kwargs):
self.user = kwargs.pop('user', None)
super(CompanyProfileForm, self).__init__(*args, **kwargs)
company_id = self.instance.id
if company_id:
comp_pic = User.objects.filter(Q(is_active=True), ~Q(is_superuser=True))
comp_pic = comp_pic.filter(Q(groups__name='AdminCompany'))
comp_pic = comp_pic.filter(Q(company_id=company_id))
self.fields['comp_pic'].queryset = comp_pic
And it's Works... without view for link url
I don't know in django-autocomplete-light, can do that.
Thanks....
django-select2 has other drawbacks, so basically it's a tradeoff, just choose whatever works best for you.
Yeah django-select2 has drawback like i said earlier is, sometimes auto generate auto.json is broken. So i want migrate to your project.
@jpic , do you have solution/example for my example code... except from doc on (https://django-autocomplete-light.readthedocs.io/en/master/) ?
Thanks
And @jpic or all , how implement FutureModelForm? there is an example? my be like my code
I'm glad you're asking, help is welcome on this topic.
Currently, I'm searching for a reasonable solution to fix travis ;)
But if you want to take over on one of the current pull requests please go ahead, it's a valuable experience !
My Case i want to set queryset from
__init__
ModelForms and deliver to UserCombo. Is there any example?------My ModelForm------
-----MySelect2View------
when get url from my view (UserCombo), display errors: ImproperlyConfigured: UserCombo is missing a QuerySet. Define UserCombo.model, UserCombo.queryset, or override UserCombo.get_queryset().
(update code modelform...) Thanks....