I’m creating a django based web app and I have used Auth > User
model (without any customization except password hiding) and for user detail I have created another model ChangeShift
. and model based form.
Case 1: When I am using alluser = ShiftChange.objects.all()
I'm able to see all the data available in ShiftChange
model.
Case 2: Now I want that when user is logging, he should be able to see data related to his name and I'm using this:
def retrieve_view(request):
# alluser = ShiftChange.objects.all()
alluser = ShiftChange.objects.filter(ShiftChange.ldap_id == request.user.username)
return render(request, 'apple/shift2.html', {'alluser': alluser})
For this code I am getting error:
cannot unpack non-iterable bool object
Error Traceback:
[21/Sep/2020 11:13:18] "GET /static/css/auth.css HTTP/1.1" 404 1662
Internal Server Error: /alldata/
Traceback (most recent call last):
File "/Library/Frameworks/Python.framework/Versions/3.8/lib/python3.8/site-packages/django/core/handlers/exception.py", line 47, in inner
response = get_response(request)
File "/Library/Frameworks/Python.framework/Versions/3.8/lib/python3.8/site-packages/django/core/handlers/base.py", line 179, in _get_response
response = wrapped_callback(request, *callback_args, **callback_kwargs)
File "/Users/shaileshyadaav/djangoshaileshdurga/mapsIT/apple/views.py", line 53, in retrieve_view
alluser = ShiftChange.objects.filter(ShiftChange.ldap_id == request.user.username)
File "/Library/Frameworks/Python.framework/Versions/3.8/lib/python3.8/site-packages/django/db/models/manager.py", line 85, in manager_method
return getattr(self.get_queryset(), name)(*args, **kwargs)
File "/Library/Frameworks/Python.framework/Versions/3.8/lib/python3.8/site-packages/django/db/models/query.py", line 942, in filter
return self._filter_or_exclude(False, *args, **kwargs)
File "/Library/Frameworks/Python.framework/Versions/3.8/lib/python3.8/site-packages/django/db/models/query.py", line 962, in _filter_or_exclude
clone._filter_or_exclude_inplace(negate, *args, **kwargs)
File "/Library/Frameworks/Python.framework/Versions/3.8/lib/python3.8/site-packages/django/db/models/query.py", line 969, in _filter_or_exclude_inplace
self._query.add_q(Q(*args, **kwargs))
File "/Library/Frameworks/Python.framework/Versions/3.8/lib/python3.8/site-packages/django/db/models/sql/query.py", line 1358, in add_q
clause, _ = self._add_q(q_object, self.used_aliases)
File "/Library/Frameworks/Python.framework/Versions/3.8/lib/python3.8/site-packages/django/db/models/sql/query.py", line 1377, in _add_q
child_clause, needed_inner = self.build_filter(
File "/Library/Frameworks/Python.framework/Versions/3.8/lib/python3.8/site-packages/django/db/models/sql/query.py", line 1255, in build_filter
arg, value = filter_expr
TypeError: cannot unpack non-iterable bool object
The line:
alluser = ShiftChange.objects.filter(
ShiftChange.ldap_id == request.user.username)
is the error. The part ShiftChange.ldap_id == request.user.username
is an expression that evaluates to True
or False
, and then your code becomes equivalent to
alluser = ShiftChange.objects.filter(True)
or
alluser = ShiftChange.objects.filter(False)
and that is probably not what you want.
Try using a single =
sign and use a valid left side kwarg (because ShiftChange.ldap_id
with the dot in the middle is not valid here). So your code may end up similar to this:
alluser = ShiftChange.objects.filter(ldap_id=request.user.username)
Collected from the Internet
Please contact javaer1[email protected] to delete if infringement.
Comments