Changed newsletter

This commit is contained in:
Zak Timson 2017-08-18 23:23:03 -04:00
parent fd433ef9f6
commit 77a9aa9424
2 changed files with 7 additions and 26 deletions

View File

@ -1,31 +1,10 @@
from django.contrib import admin from django.contrib import admin
from django.contrib.auth.admin import User
from django.utils import timezone from django.utils import timezone
from .models import Newsletter, NewsletterSubscription from .models import Newsletter, Subscriber
class SubscriberInline(admin.StackedInline): admin.site.register(Subscriber)
can_delete = False
extra = 1
fields = ['subscribed']
max_num = 1
model = NewsletterSubscription
class ExtendUserAdmin(admin.ModelAdmin):
list_display = ['username', 'first_name', 'last_name', 'email', 'date_joined', 'newsletter', 'is_staff', 'is_superuser']
search_fields = ['username', 'first_name', 'last_name', 'email']
list_filter = ['is_staff', 'is_superuser']
inlines = [SubscriberInline]
def newsletter(self, obj):
return bool(True)
newsletter.boolean = True
admin.site.unregister(User)
admin.site.register(User, ExtendUserAdmin)
@admin.register(Newsletter) @admin.register(Newsletter)

View File

@ -14,6 +14,8 @@ class Newsletter(models.Model):
return self.subject return self.subject
class NewsletterSubscription(models.Model): class Subscriber(models.Model):
user = models.OneToOneField(User, on_delete=models.CASCADE) email = models.EmailField()
subscribed = models.BooleanField(default=False)
def __str__(self):
return self.email