pythondjangodjango-modelsdjango-admindjango-admin-actions

Passing User Data to Admin Actions in Django


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?


Solution

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