Added sent flag to newsletter to determine if newsletter has been sent out to subscribers yet
This commit is contained in:
parent
319a5ff2c4
commit
7844760720
BIN
db.sqlite3
BIN
db.sqlite3
Binary file not shown.
@ -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 = []
|
||||||
|
@ -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):
|
||||||
|
@ -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})
|
||||||
|
Loading…
Reference in New Issue
Block a user