I have the following model:
class Item(models.Model):
user = models.ForeignKey(settings.AUTH_USER_MODEL, blank=True, null=True, related_name='item',on_delete=models.SET_NULL)
email = models.BooleanField(blank=True, null=True)
.....
I need to send an email to user
, where Item
email
attribute is False
.
I have the following query:
items = Item.objects.filter(email=False)
I want to filter/group item by User. I want to do it python because I want to send emails with delay and not to overwhelm the database at once with many queries.
For each use I want to create a context
dictionary that I can sent to the Django Email.
A pseudo code/logic:
user_context {
'subject' : 'some subject'}
for item in items:
if user is the same:
user_context['content] = append item
if finished same_user items:
send_email(user_context)
context = {} # reset context