Added sent flag to newsletter to determine if newsletter has been sent out to subscribers yet

This commit is contained in:
Zak Timson 2017-09-03 18:06:59 -04:00
parent 319a5ff2c4
commit 7844760720
4 changed files with 6 additions and 5 deletions

Binary file not shown.

View File

@ -14,11 +14,11 @@ class NewsletterAdmin(admin.ModelAdmin):
def get_form(self, request, obj=None, **kwargs): def get_form(self, request, obj=None, **kwargs):
if obj: if obj:
self.fields = ['creator', 'subject', 'body', 'publish'] self.fields = ['creator', 'subject', 'body', 'sent', 'publish']
if obj.publish < timezone.now(): if obj.sent:
self.readonly_fields = ['creator', 'subject', 'body', 'publish'] self.readonly_fields = ['creator', 'subject', 'body', 'sent', 'publish']
else: else:
self.readonly_fields = ['creator'] self.readonly_fields = ['creator', 'sent']
else: else:
self.fields = ['subject', 'body', 'publish'] self.fields = ['subject', 'body', 'publish']
self.readonly_fields = [] self.readonly_fields = []

View File

@ -8,6 +8,7 @@ class Newsletter(models.Model):
created = models.DateTimeField(auto_now_add=True) created = models.DateTimeField(auto_now_add=True)
creator = models.ForeignKey(User) creator = models.ForeignKey(User)
publish = models.DateTimeField(default=now()) publish = models.DateTimeField(default=now())
sent = models.BooleanField(default=False)
subject = models.CharField(max_length=255) subject = models.CharField(max_length=255)
def __str__(self): def __str__(self):

View File

@ -4,5 +4,5 @@ from .models import Newsletter
def newsletters(request): def newsletters(request):
newsletters = Newsletter.objects.all().order_by('-publish') newsletters = Newsletter.objects.filter(sent=True).order_by('-publish')
return render(request, 'newsletters.html', {'newsletters': newsletters}) return render(request, 'newsletters.html', {'newsletters': newsletters})