Kerosive Kerosive - 1 year ago 336
Python Question

missing 1 required positional argument: 'queryset'

I am attempting to update an extended user model

in 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)



Internal Server Error: /admin/auth/user/
Traceback (most recent call last):
File "/usr/local/lib/python3.5/site-packages/django/core/handlers/", line 39, in inner
response = get_response(request)
File "/usr/local/lib/python3.5/site-packages/django/core/handlers/", line 187, in _get_response
response = self.process_exception_by_middleware(e, request)
File "/usr/local/lib/python3.5/site-packages/django/core/handlers/", line 185, in _get_response
response = wrapped_callback(request, *callback_args, **callback_kwargs)
File "/usr/local/lib/python3.5/site-packages/django/contrib/admin/", line 544, in wrapper
return self.admin_site.admin_view(view)(*args, **kwargs)
File "/usr/local/lib/python3.5/site-packages/django/utils/", line 149, in _wrapped_view
response = view_func(request, *args, **kwargs)
File "/usr/local/lib/python3.5/site-packages/django/views/decorators/", line 57, in _wrapped_view_func
response = view_func(request, *args, **kwargs)
File "/usr/local/lib/python3.5/site-packages/django/contrib/admin/", line 211, in inner
return view(request, *args, **kwargs)
File "/usr/local/lib/python3.5/site-packages/django/utils/", line 67, in _wrapper
return bound_func(*args, **kwargs)
File "/usr/local/lib/python3.5/site-packages/django/utils/", line 149, in _wrapped_view
response = view_func(request, *args, **kwargs)
File "/usr/local/lib/python3.5/site-packages/django/utils/", line 63, in bound_func
return func.__get__(self, type(self))(*args2, **kwargs2)
File "/usr/local/lib/python3.5/site-packages/django/contrib/admin/", 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/", 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 Source

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

Recommended from our users: Dynamic Network Monitoring from WhatsUp Gold from IPSwitch. Free Download