I'm using django-allauth and I have a question. In order to filter the data in my adminsite for my User model I use following code:
def get_queryset(self, request):
qs = super(UserAdmin, self).get_queryset(request)
if request.user.is_superuser:
return qs
return qs.filter(profile__country=request.user.profile.country)
It lets the adminusers (not superusers) only see the tables from users in their country.
I would also like to filter the data in the standard column created by allauth called "Accounts" - > "Email Addresses" but I don't know which queryset that would be. I would be thankful for any tip.
Have a nice day guys!
Solution here: ->
admin.py looks like this :
from allauth.account.models import EmailAddress
from allauth.account.admin import EmailAddressAdmin
class CustomAllauthAdmin(EmailAddressAdmin):
def get_queryset(self, request):
qs = super(EmailAddressAdmin, self).get_queryset(request)
if request.user.is_superuser:
return qs
return qs.filter(user__profile__country=request.user.profile.country)
admin.site.unregister(EmailAddress)
admin.site.register(EmailAddress, CustomAllauthAdmin)