Skip to content

Newsletter Models

NewsLetterSubscriber Model

The NewsLetterSubscriber model represents a user who subscribes to a newsletter. It stores their email address and ensures that the email is unique.


Fields

Field Type Required Description
email EmailField Yes A unique email address for the subscriber.

Custom Methods

  • __str__: This method returns the email of the subscriber.

SubscribedNewsLetterType Model

The SubscribedNewsLetterType model represents the relationship between a subscriber and the newsletter type they are subscribed to. It also tracks the subscription status.


Fields

Field Type Required Description
subscriber ForeignKey Yes A foreign key to the NewsLetterSubscriber model, representing the subscriber.
newsletter_type ForeignKey Yes A foreign key to the NewsLetterType model, representing the type of newsletter.
is_subscribed BooleanField No A boolean indicating whether the subscriber is currently subscribed to the newsletter (default: True).

Custom Methods

  • __str__: This method returns a string that combines the subscriber's email and the newsletter type.

NewsLetter Model

The NewsLetter model represents a newsletter. It stores the title, description, banner image, type, active status, and the period during which the newsletter is active.


Fields

Field Type Required Description
title CharField Yes The title of the newsletter.
description TextField No A description of the newsletter's content.
banner_image ImageField No A banner image for the newsletter.
newsletter_type ForeignKey Yes A foreign key to the NewsLetterType model, representing the type of newsletter.
is_active BooleanField No A boolean indicating whether the newsletter is currently active.
start_at DateTimeField No The start date of the newsletter's availability.
end_at DateTimeField No The end date of the newsletter's availability.
created_at DateTimeField Yes Auto-generated timestamp when the newsletter was created.
updated_at DateTimeField Yes Auto-generated timestamp when the newsletter was last updated.

Custom Methods

  • __str__: This method returns the title of the newsletter.

PublishNewsLetter Model

The PublishNewsLetter model represents the publishing of a newsletter to a subscriber. It stores the timestamp of when the newsletter was sent to the subscriber.


Fields

Field Type Required Description
subscribed_newsletter_type ForeignKey Yes A foreign key to the SubscribedNewsLetterType model, representing the subscriber's subscription.
newsletter ForeignKey Yes A foreign key to the NewsLetter model, representing the newsletter being published.
email_sent_at DateTimeField Yes Auto-generated timestamp indicating when the newsletter was sent.

Custom Methods

  • __str__: This method returns the email of the subscriber.