0

I am attempting to write an admin action that accesses data from selected users. i.e. user's email. However, I have only been able to access the instance/data of the user that is currently logged in.

For example, to access the emails of selected users, I have tried:

#models.py

class Account(AbstractBaseUser):
    email = models.EmailField(max_length=60, unique=True)

#admin.py

from account.models import Account

for Account in queryset:
    author = request.Account.email
    #OR     
    author = Account.objects.get(email=request.email)
    print(author)

and both of these will fill "author" with the email address of the admin that is trying to pull the data.

Does anyone know how I could pull data from selected accounts with an admin action?

Display name
  • 753
  • 10
  • 28
  • Try `author = Account.objects.get(email=request.user.email)` in one-line without for-loop. Also, You will need to make custom authentication. More [here](https://docs.djangoproject.com/en/3.0/topics/auth/customizing/) – ifrag Apr 22 '20 at 20:52
  • Thank you for the idea but this gave me the same results as above – Display name Apr 22 '20 at 21:00

1 Answers1

0

I was really overcomplicating it. Ironically enough, I found the answer on this site called simpleisbetterthatcomplex. The proper format was

for Account in queryset:
    print(Account.email)
Display name
  • 753
  • 10
  • 28