Skip to content

Conversation

@Bhavishya-Chaturvedi
Copy link

Added two models in the mailer app. The structure of the models are listed below:

EmailRecord:
id = auto generated
email_address = charater
created_at = DateTimeField(auto_now_add=True)
status = CharField(max_length=20, choices=[('pending'), ('sent',), ('failed',), ], default='pending') # status of the mail
sent_at = DateTimeField(null=True, blank=True)
error_message = extField(null=True, blank=True) # optional for better error handling

EmailContent:
id = auto generated
subject = CharField(max_length=255)
mail_body = TextField()
email_records = ManyToManyField( EmailRecord,) #Foreign key for EmailRecord table
created_at = DateTimeField(auto_now_add=True)
user_id = ForeignKey( 'auth.User', on_delete=models.CASCADE,) #Foreign key for auth users

Comment on lines 13 to 21
status = models.CharField(
max_length=20,
choices=[
('pending'),
('sent',),
('failed',),
],
default='pending'
)
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Define choices in tuple, and then use it in choices.
STATUS_CHOICES = [
('pending', 'Pending'),
('sent', 'Sent'),
('failed', 'Failed'),
]

Stores individual email addresses and their sending status.
Each row corresponds to one email address from the uploaded CSV file.
"""
email_address = models.EmailField(unique=True)
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

remove unique constrained as multiple mails can be sent to the same email

related_name='email_contents'
)
created_at = models.DateTimeField(auto_now_add=True)
user_id = models.ForeignKey(
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The field name should be user, not user_id. Django automatically creates _id in the database column.

)
created_at = models.DateTimeField(auto_now_add=True)
user_id = models.ForeignKey(
'auth.User',
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Import explicitly
from django.contrib.auth.models import User

and then user User as fk

Stores individual email addresses and their sending status.
Each row corresponds to one email address from the uploaded CSV file.
"""
email_address = models.EmailField(unique=True)
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Consider adding for faster lookups by email.:

class Meta:
indexes = [models.Index(fields=['email_address'])]

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants