Commit 7d222881 authored by Luko van der Maas's avatar Luko van der Maas
Browse files

added a category field and added it to the admin with filtering

parent 029975ca
......@@ -30,18 +30,18 @@ class DeviceAdmin(admin.ModelAdmin):
@admin.register(models.Message)
class MessageAdmin(admin.ModelAdmin):
list_display = ('title', 'body', 'sent', 'success', 'failure')
list_display = ('title', 'body', 'category', 'sent', 'success', 'failure')
filter_horizontal = ('users',)
list_filter = ('sent',)
list_filter = ('sent', 'category')
def get_fields(self, request, obj=None):
if obj and obj.sent:
return 'users', 'title', 'body', 'success', 'failure'
return 'users', 'title', 'body'
return 'users', 'title', 'body', 'category', 'success', 'failure'
return 'users', 'title', 'body', 'category'
def get_readonly_fields(self, request, obj=None):
if obj and obj.sent:
return 'users', 'title', 'body', 'success', 'failure'
return 'users', 'title', 'body', 'category', 'success', 'failure'
return super().get_readonly_fields(request, obj)
def change_view(self, request, object_id, form_url='', **kwargs):
......
# -*- coding: utf-8 -*-
# Generated by Django 1.11.7 on 2017-12-13 19:22
from __future__ import unicode_literals
from django.db import migrations, models
class Migration(migrations.Migration):
dependencies = [
('pushnotifications', '0002_auto_20171103_1658'),
]
operations = [
migrations.AddField(
model_name='message',
name='category',
field=models.CharField(choices=[('general', 'General'), ('pizza', 'Pizza'), ('event', 'Events'), ('newsletter', 'Newsletter'), ('sponsor', 'Sponsored messages'), ('photo', "Photo's"), ('board', 'Board')], default='general', max_length=10),
),
]
......@@ -36,6 +36,15 @@ class Device(models.Model):
class Message(models.Model):
CATEGORIES = (
("general", "General"),
("pizza", "Pizza"),
("event", "Events"),
("newsletter", "Newsletter"),
("sponsor", "Sponsored messages"),
("photo", "Photo's"),
("board", "Board"),
)
users = models.ManyToManyField(django_settings.AUTH_USER_MODEL)
title = models.CharField(
......@@ -46,6 +55,8 @@ class Message(models.Model):
verbose_name=_('body')
)
category = models.CharField(choices=CATEGORIES, max_length=10, default="general")
sent = models.BooleanField(
verbose_name=_('sent'),
default=False
......
Markdown is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment