Kerosive Kerosive - 23 days ago 9
Python Question

missing 1 required positional argument: 'queryset'

I am attempting to update an extended user model

profile
in admin.py actions. I have been researching this for a couple hours now and have come up short. I am receiving a
pc_add_1() missing 1 required positional argument: 'queryset'
error, please help.

class ProfileAdminInLine(admin.StackedInline):
model = Profile


class ProfileAdmin(UserAdmin):
list_display = ['username', 'email', 'first_name', 'last_name', 'is_staff',
'rewards_punch_card', 'rewards_tier', 'lularippee_credits']
list_select_related = True
inlines = [ProfileAdminInLine]

actions = ['pc_add_1', 'pc_add_2', 'pc_add_3', 'pc_add_4', 'pc_add_5',
'pc_add_6', 'pc_add_7', 'pc_add_8', 'pc_add_9']

def rewards_tier(self, user):
return user.profile.rewards_tier

def rewards_punch_card(self, user):
return user.profile.rewards_current

def lularippee_credits(self, user):
return user.profile.rewards_credits

def pc_add_1(self, request, user, queryset):

punch_card = user.profile.rewards_current
tier = user.profile.rewards_tier
credits = user.profile.rewards_credits

punch_cards_updated = queryset.update(punch_card + 1)

if punch_cards_updated == 10:
queryset.update(punch_card == 0)
if tier == 1:
queryset.update(tier + 1)
queryset.update(credits + 25)
elif tier == 2:
queryset.update(tier + 1)
queryset.update(credits + 35)
elif tier == 3:
queryset.update(tier + 1)
queryset.update(credits + 45)
elif tier == 4:
queryset.update(tier + 1)
queryset.update(credits + 55)
elif tier == 5:
queryset.update(credits + 65)
elif tier == 6:
queryset.update(credits + 65)

else:
pass


traceback

Internal Server Error: /admin/auth/user/
Traceback (most recent call last):
File "/usr/local/lib/python3.5/site-packages/django/core/handlers/exception.py", line 39, in inner
response = get_response(request)
File "/usr/local/lib/python3.5/site-packages/django/core/handlers/base.py", line 187, in _get_response
response = self.process_exception_by_middleware(e, request)
File "/usr/local/lib/python3.5/site-packages/django/core/handlers/base.py", line 185, in _get_response
response = wrapped_callback(request, *callback_args, **callback_kwargs)
File "/usr/local/lib/python3.5/site-packages/django/contrib/admin/options.py", line 544, in wrapper
return self.admin_site.admin_view(view)(*args, **kwargs)
File "/usr/local/lib/python3.5/site-packages/django/utils/decorators.py", line 149, in _wrapped_view
response = view_func(request, *args, **kwargs)
File "/usr/local/lib/python3.5/site-packages/django/views/decorators/cache.py", line 57, in _wrapped_view_func
response = view_func(request, *args, **kwargs)
File "/usr/local/lib/python3.5/site-packages/django/contrib/admin/sites.py", line 211, in inner
return view(request, *args, **kwargs)
File "/usr/local/lib/python3.5/site-packages/django/utils/decorators.py", line 67, in _wrapper
return bound_func(*args, **kwargs)
File "/usr/local/lib/python3.5/site-packages/django/utils/decorators.py", line 149, in _wrapped_view
response = view_func(request, *args, **kwargs)
File "/usr/local/lib/python3.5/site-packages/django/utils/decorators.py", line 63, in bound_func
return func.__get__(self, type(self))(*args2, **kwargs2)
File "/usr/local/lib/python3.5/site-packages/django/contrib/admin/options.py", line 1569, in changelist_view
response = self.response_action(request, queryset=cl.get_queryset(request))
File "/usr/local/lib/python3.5/site-packages/django/contrib/admin/options.py", line 1305, in response_action
response = func(self, request, queryset)
TypeError: pc_add_1() missing 1 required positional argument: 'queryset'
[13/Nov/2016 15:16:52] "POST /admin/auth/user/ HTTP/1.1" 500 106710

Answer

You have the method signature wrong:

def pc_add_1(self, request, user, queryset):

For admin actions it should be

def pc_add_1(self, request, queryset):

now if you want to know which admin user is making the change you can find that out from request.user