celiao / django-rest-authemail

A RESTful API for user signup and authentication using email addresses.
GNU General Public License v3.0
315 stars 92 forks source link

has_add_permission() takes 2 positional arguments but 3 were given #32

Closed leunis closed 2 years ago

leunis commented 3 years ago

I am getting this error when I click on a user in the admin.

'TypeError at /admin/core/user/1/change/ has_add_permission() takes 2 positional arguments but 3 were given'

I am a newbee in programming and in Django but I found on the internet that is has to to with inlines. So I have overwritten inlines in my custom EmailUserAdmin like so

class MyUserAdmin(EmailUserAdmin):
    fieldsets = (
        (None, {'fields': ('email', 'password')}),
        ('Personal Info', {'fields': ('first_name',
                                      'last_name',
                                      'is_company')}),
        ('Permissions', {'fields': ('is_active', 'is_staff',
                                    'is_superuser', 'is_verified')}),
        ('Important dates', {'fields': ('last_login', 'date_joined')}),
    )
    inlines = []

Of course I am missing some features now but the error is gone. How should I Solve this properly. This are my packages:

Django>= 3.1.1
djangorestframework>=3.9.0
psycopg2-binary
dj-database-url
gunicorn
django-cors-headers>=3.7.0
flake8>=3.6.0,<3.7.0
postmarker
django-rest-authemail
leunis commented 3 years ago

Hi, I changed back to django 2.2.18. No problem here. So I guess something with has_permissions has changed in django 3.x

DeeeeLAN commented 3 years ago

Django 3.x modified django/contrib/admin/options.py at line 603:

if not inline.has_add_permission(request, obj):

Updating all the authemail admin.py has_add_permissions from:

def has_add_permission(self, request):
    return False

to:

def has_add_permission(self, request, obj=None):
    return False

Fixes it for me on 3.x.

pesfahanian commented 3 years ago

Django 3.x modified django/contrib/admin/options.py at line 603:

if not inline.has_add_permission(request, obj):

Updating all the authemail admin.py has_add_permissions from:

def has_add_permission(self, request):
    return False

to:

def has_add_permission(self, request, obj=None):
    return False

Fixes it for me on 3.x.

Thanks! This worked fine.

DeeeeLAN commented 3 years ago

I am pretty sure that by giving it a default (obj=None), it will work fine with either version.

svandegar commented 3 years ago

Thanks @DeeeeLAN, it worked fine for me.

@celiao , any plan on merging the PR #41 ?

kaepyro commented 3 years ago

Thanks, it worked me too! Please merge PR #41 .

svandegar commented 3 years ago

@celiao , would you mind having other mainteners joining the project, if you don't have time to review/merge PR's?

I'm happy to help!

arielaco commented 2 years ago

Worked for me too. Bumping this.

celiao commented 2 years ago

Closed by #41