forked from itsee-birmingham/django_wce_api_tests
-
Notifications
You must be signed in to change notification settings - Fork 0
/
models.py
222 lines (166 loc) · 6.59 KB
/
models.py
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
from django.db import models
from django.conf import settings
from api.models import BaseModel
class Author (BaseModel):
AVAILABILITY = 'public'
REQUIRED_FIELDS = ['identifier', 'name']
SERIALIZER = 'AuthorSerializer'
identifier = models.TextField('Identifier', unique=True)
name = models.TextField('Name', blank=True)
age = models.IntegerField('Age', null=True, blank=True)
date_joined = models.DateField('Date Joined', null=True)
active = models.BooleanField('Active', null=True)
def get_serialization_fields():
fields = '__all__'
return fields
def get_fields():
data = {}
fields = list(Author._meta.get_fields(include_hidden=True))
for field in fields:
data[field.name] = field.get_internal_type()
return data
class Meta:
ordering = ['identifier']
class Work (BaseModel):
AVAILABILITY = 'public'
SERIALIZER = 'WorkSerializer'
identifier = models.TextField('Identifier', blank=True)
title = models.TextField('Title', blank=True)
author = models.ForeignKey('Author',
models.PROTECT,
related_name='works')
def get_serialization_fields():
fields = '__all__'
return fields
def get_fields():
data = {}
fields = list(Work._meta.get_fields(include_hidden=True))
for field in fields:
data[field.name] = field.get_internal_type()
return data
class Review (BaseModel):
AVAILABILITY = 'private'
SERIALIZER = 'ReviewSerializer'
notes = models.TextField('Notes', null=True, blank=True)
score = models.IntegerField('Score', null=True, blank=True)
work = models.ForeignKey('Work',
models.PROTECT,
related_name='reviews')
user = models.ForeignKey(settings.AUTH_USER_MODEL,
models.PROTECT,
related_name='reviewers')
def get_serialization_fields():
fields = '__all__'
return fields
def get_fields():
data = {}
fields = list(Review._meta.get_fields(include_hidden=True))
for field in fields:
data[field.name] = field.get_internal_type()
return data
class Decision (BaseModel):
AVAILABILITY = 'public_or_user'
SERIALIZER = 'DecisionSerializer'
work = models.ForeignKey('Work',
models.PROTECT,
related_name='decision')
accept = models.BooleanField(null=True)
summary_notes = models.TextField('Notes', null=True, blank=True)
public = models.BooleanField(null=True)
user = models.ForeignKey(settings.AUTH_USER_MODEL,
models.PROTECT,
related_name='decider')
def get_serialization_fields():
fields = '__all__'
return fields
def get_fields():
data = {}
fields = list(Decision._meta.get_fields(include_hidden=True))
for field in fields:
data[field.name] = field.get_internal_type()
return data
class Project (BaseModel):
AVAILABILITY = 'public'
managing_editor = models.ForeignKey(settings.AUTH_USER_MODEL,
models.PROTECT,
related_name='manager')
editors = models.ManyToManyField(settings.AUTH_USER_MODEL,
related_name='editor_of',
blank=True)
status = models.TextField('Status', null=True, blank=True)
genre = models.TextField('Genre', null=True, blank=True)
work = models.ManyToManyField('Work',
related_name='included_in',
blank=True)
def get_fields():
data = {}
fields = list(Decision._meta.get_fields(include_hidden=True))
for field in fields:
data[field.name] = field.get_internal_type()
return data
def get_user_fields():
user_fields = ['editors', 'managing_editor']
data = {}
fields = list(Project._meta.get_fields(include_hidden=True))
for field in fields:
if field.name in user_fields:
data[field.name] = field.get_internal_type()
return data
class PublicationPlan (BaseModel):
AVAILABILITY = 'project'
SERIALIZER = 'PublicationPlanSerializer'
project = models.ForeignKey('Project',
models.PROTECT,
related_name='plan')
current_stage = models.TextField('Stage', null=True, blank=True)
notes = models.TextField('Notes', null=True, blank=True)
public = models.BooleanField(null=True)
user = models.ForeignKey(settings.AUTH_USER_MODEL,
models.PROTECT,
null=True,
related_name='plan_creator')
editors = models.ManyToManyField('Editor',
blank=True)
def get_serialization_fields():
fields = '__all__'
return fields
def get_fields():
data = {}
fields = list(PublicationPlan._meta.get_fields(include_hidden=True))
for field in fields:
data[field.name] = field.get_internal_type()
return data
class Editor (BaseModel):
AVAILABILITY = 'logged_in'
SERIALIZER = 'EditorSerializer'
user = models.ForeignKey(settings.AUTH_USER_MODEL,
models.PROTECT,
null=True)
active = models.BooleanField(null=True)
def get_serialization_fields():
fields = '__all__'
return fields
def get_fields():
data = {}
fields = list(Editor._meta.get_fields(include_hidden=True))
for field in fields:
data[field.name] = field.get_internal_type()
return data
class Edition (BaseModel):
SERIALIZER = 'EditionSerializer'
identifier = models.TextField('Identifier', blank=True)
work = models.ForeignKey('Work',
models.PROTECT,
related_name='editions')
year = models.IntegerField('Year', null=True)
place = models.TextField('Place', blank=True)
volume = models.TextField('Volume', blank=True)
def get_serialization_fields():
fields = '__all__'
return fields
def get_fields():
data = {}
fields = list(Edition._meta.get_fields(include_hidden=True))
for field in fields:
data[field.name] = field.get_internal_type()
return data