-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathmodels.py
More file actions
134 lines (114 loc) · 3.44 KB
/
Copy pathmodels.py
File metadata and controls
134 lines (114 loc) · 3.44 KB
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
from django.db import models
class Agency(models.Model):
"""
Represents a federal agency or sub-agency with CFR references
"""
name = models.CharField(max_length=255)
# bug in API: Agency w/ short_name "Military Compensation and Retirement Modernization Commission"
short_name = models.CharField(max_length=63, blank=True, null=True)
display_name = models.CharField(max_length=255)
sortable_name = models.CharField(max_length=255)
slug = models.SlugField(max_length=255, unique=True)
cfr_word_count = models.BigIntegerField(
null=True,
blank=True,
default=0,
help_text="Total word count of all related CFR reference full texts",
)
# Self-referential relationship for parent/child agencies
parent = models.ForeignKey(
"self",
null=True,
blank=True,
on_delete=models.CASCADE,
related_name="children",
)
class Meta:
verbose_name_plural = "agencies"
ordering = ["sortable_name"]
def __str__(self):
return self.display_name
class CFRReferenceManager(models.Manager):
def get_queryset(self):
return super().get_queryset().defer("full_text")
class CFRReference(models.Model):
"""
Represents a Code of Federal Regulations (CFR) reference for an Agency
"""
objects = CFRReferenceManager()
# foreign keys
agency = models.ForeignKey(
Agency,
on_delete=models.CASCADE,
related_name="cfr_references",
)
# metadata
title = models.ForeignKey(
"Title",
on_delete=models.CASCADE,
related_name="cfr_references",
)
subtitle = models.CharField(
max_length=25,
blank=True,
null=True,
)
chapter = models.CharField(
max_length=25,
blank=True,
null=True,
)
subchapter = models.CharField(
max_length=25,
blank=True,
null=True,
)
part = models.CharField(
max_length=25,
blank=True,
null=True,
)
subpart = models.CharField(
max_length=25,
blank=True,
null=True,
)
section = models.CharField(
max_length=20,
blank=True,
)
# text to be processed for word count
full_text = models.TextField(blank=True, null=True)
last_updated = models.DateTimeField(null=True)
class Meta:
unique_together = [
"agency",
"title",
"chapter",
"subtitle",
"part",
"subchapter",
]
ordering = ["title", "chapter"]
def __str__(self):
parts = [f"Title {self.title}"]
if self.subtitle:
parts.append(f"Subtitle {self.subtitle}")
if self.chapter:
parts.append(f"Chapter {self.chapter}")
if self.subchapter:
parts.append(f"Subchapter {self.subchapter}")
if self.part:
parts.append(f"Part {self.part}")
return ", ".join(parts)
class Title(models.Model):
number = models.IntegerField(primary_key=True)
name = models.CharField(max_length=255)
latest_amended_on = models.DateField(null=True, blank=True)
latest_issue_date = models.DateField(null=True, blank=True)
up_to_date_as_of = models.DateField(null=True, blank=True)
reserved = models.BooleanField(default=False)
class Meta:
ordering = ["number"]
def __str__(self):
return f"{self.number} - {self.name}"