Skip to content
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

issue with model choice queryset override #749

Closed
neokeats opened this issue Jul 10, 2017 · 4 comments
Closed

issue with model choice queryset override #749

neokeats opened this issue Jul 10, 2017 · 4 comments

Comments

@neokeats
Copy link

neokeats commented Jul 10, 2017

hi
before break changes on 1.0, i was able to do :

class Myfilter(django_filters.FilterSet): 
       def __init__(self, *args, **kwargs):
              self.users = kwargs.pop('users', None)
              super(ContractFilter, self).__init__(*args, **kwargs)
              self.filters['user'].extra.update({
                   'queryset': User.objects.filter(pk__in=self.users).order_by('last_name', 'first_name'),
                   'empty_label': '',
                   'help_text': False
               })

it's now ignored so i replaced it with :

def user_filter(request):
       users = get_team_users_ids(request)
       return User.objects.filter(pk__in=users).order_by('last_name', 'first_name').all()

class Myfilter(django_filters.FilterSet): 
       user = django_filters.filters.ModelChoiceFilter(queryset=user_filter)
       def __init__(self, *args, **kwargs):
              super(ContractFilter, self).__init__(*args, **kwargs)

but it's not working i gat an error :

self.filter = self.filter_class(self.request.GET, queryset=qs)
  File "C:\Taf\__ENV\elypsys\lib\site-packages\django_filters\filterset.py", line 186, in __init__
    self.filters = copy.deepcopy(self.base_filters)
  File "C:\Taf\__ENV\elypsys\lib\copy.py", line 182, in deepcopy
    y = _reconstruct(x, rv, 1, memo)
  File "C:\Taf\__ENV\elypsys\lib\copy.py", line 320, in _reconstruct
    value = deepcopy(value, memo)
  File "C:\Taf\__ENV\elypsys\lib\copy.py", line 182, in deepcopy
    y = _reconstruct(x, rv, 1, memo)
  File "C:\Taf\__ENV\elypsys\lib\copy.py", line 297, in _reconstruct
    state = deepcopy(state, memo)
  File "C:\Taf\__ENV\elypsys\lib\copy.py", line 155, in deepcopy
    y = copier(x, memo)
  File "C:\Taf\__ENV\elypsys\lib\copy.py", line 243, in _deepcopy_dict
    y[deepcopy(key, memo)] = deepcopy(value, memo)
  File "C:\Taf\__ENV\elypsys\lib\copy.py", line 155, in deepcopy
    y = copier(x, memo)
  File "C:\Taf\__ENV\elypsys\lib\copy.py", line 243, in _deepcopy_dict
    y[deepcopy(key, memo)] = deepcopy(value, memo)
  File "C:\Taf\__ENV\elypsys\lib\copy.py", line 182, in deepcopy
    y = _reconstruct(x, rv, 1, memo)
  File "C:\Taf\__ENV\elypsys\lib\copy.py", line 306, in _reconstruct
    y.__dict__.update(state)
AttributeError: 'NoneType' object has no attribute 'update'

thanx

@rpkilby
Copy link
Collaborator

rpkilby commented Jul 10, 2017

Hi @neokeats - could you install the branch from #680? It fixes a number of issues related to choice handling.

@neokeats
Copy link
Author

hi,

pip install --upgrade git+https://github.com/rpkilby/django-filter.git
Collecting git+https://github.com/rpkilby/django-filter.git
  Cloning https://github.com/rpkilby/django-filter.git to c:\users\neoke\appdata\local\temp\pip-ahwvkr_g-build
Installing collected packages: django-filter
  Found existing installation: django-filter 1.0.4
    Uninstalling django-filter-1.0.4:
      Successfully uninstalled django-filter-1.0.4
  Running setup.py install for django-filter ... done
Successfully installed django-filter-1.0.4

still the same issue

@neokeats
Copy link
Author

Hi,
sorry, forget all, it was a totally unrelated issue.
the autocomplete did :
from filters import user_filter
instead of
from filters.user_filter import user_filter
so it was the file instead of the function that was used.

thanx

@rami-alloush
Copy link

The code in your original question helped me a lot! Thanks.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

4 participants