[Answered ]-QuerySet confusion in Django Admin

2👍

That’s not quite how Python for loops work. You want something like:

    for employee in queryset:
        message = loader.get_template('email.txt')
        messageContext = Context({
            'name': employee.name
        })
        send_mail('Test Subject Line', message.render(messageContext), 'me@test.com', [employee.address],
                  fail_silently=False)

The point is that queryset provides multiple instances of your employeeEmail model. When you run a for loop over the queryset, employee gets bound to each of them in sequence.

Leave a comment