Skip to content
GitLab
Projects
Groups
Snippets
/
Help
Help
Support
Community forum
Keyboard shortcuts
?
Submit feedback
Contribute to GitLab
Sign in
Toggle navigation
Menu
Open sidebar
thalia
concrexit
Commits
7d222881
Commit
7d222881
authored
Dec 13, 2017
by
Luko van der Maas
Browse files
added a category field and added it to the admin with filtering
parent
029975ca
Changes
3
Hide whitespace changes
Inline
Side-by-side
website/pushnotifications/admin.py
View file @
7d222881
...
...
@@ -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
):
...
...
website/pushnotifications/migrations/0003_message_category.py
0 → 100644
View file @
7d222881
# -*- 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
),
),
]
website/pushnotifications/models.py
View file @
7d222881
...
...
@@ -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
...
...
Write
Preview
Supports
Markdown
0%
Try again
or
attach a new file
.
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Cancel
Please
register
or
sign in
to comment