feature: add a Category model

- add a Category model that represents the CCE
  defined categories for various legislation
This commit is contained in:
stupidcomputer 2024-07-24 13:13:07 -05:00
parent c92fbf0890
commit 25881d4cb3
6 changed files with 54 additions and 3 deletions

View File

@ -15,6 +15,7 @@ to_register = [
[models.School], [models.School],
[models.Country], [models.Country],
[models.Sponsor], [models.Sponsor],
[models.Category],
] ]
for i in to_register: for i in to_register:
admin.site.register(*i) admin.site.register(*i)

View File

@ -0,0 +1,26 @@
# Generated by Django 4.2.14 on 2024-07-24 17:58
from django.db import migrations, models
import django.db.models.deletion
class Migration(migrations.Migration):
dependencies = [
('explorer', '0001_initial'),
]
operations = [
migrations.CreateModel(
name='Category',
fields=[
('id', models.BigAutoField(auto_created=True, primary_key=True, serialize=False, verbose_name='ID')),
('name', models.CharField(max_length=256)),
],
),
migrations.AlterField(
model_name='legislativetext',
name='category',
field=models.ForeignKey(on_delete=django.db.models.deletion.CASCADE, to='explorer.category'),
),
]

View File

@ -54,6 +54,19 @@ class Sponsor(models.Model):
our_name = __class__.__name__ our_name = __class__.__name__
return reverse("{}.detail".format(our_name), kwargs={"model_id": self.id}) return reverse("{}.detail".format(our_name), kwargs={"model_id": self.id})
class Category(models.Model):
name = models.CharField(max_length=256)
class Meta:
verbose_name_plural = "Categories"
def __str__(self):
return "{}".format(self.name)
def get_absolute_url(self):
our_name = __class__.__name__
return reverse("{}.detail".format(our_name), kwargs={"model_id": self.id})
class LegislationBook(models.Model): class LegislationBook(models.Model):
class Meta: class Meta:
verbose_name = "Book" verbose_name = "Book"
@ -105,6 +118,10 @@ class LegislationBook(models.Model):
text["country"] = text["country"].replace(" 2", "") text["country"] = text["country"].replace(" 2", "")
text["country"] = InstantiateIfNone(Country, text["country"]) text["country"] = InstantiateIfNone(Country, text["country"])
if not text["category"] or text["category"] == "Select One--":
text["category"] = "No category"
text["category"] = InstantiateIfNone(Category, text["category"])
sponsors = text["sponsors"].split(', ') sponsors = text["sponsors"].split(', ')
sponsors = [InstantiateIfNone(Sponsor, sponsor) for sponsor in sponsors] sponsors = [InstantiateIfNone(Sponsor, sponsor) for sponsor in sponsors]
@ -146,7 +163,7 @@ class LegislativeText(models.Model):
text = models.TextField() text = models.TextField()
year = models.IntegerField() year = models.IntegerField()
committee = models.IntegerField() committee = models.IntegerField()
category = models.CharField(max_length=256) category = models.ForeignKey(Category, on_delete=models.CASCADE)
docket_order = models.IntegerField() docket_order = models.IntegerField()
school = models.ForeignKey(School, on_delete=models.CASCADE) school = models.ForeignKey(School, on_delete=models.CASCADE)
sponsors = models.ManyToManyField(Sponsor, blank=True) sponsors = models.ManyToManyField(Sponsor, blank=True)
@ -203,4 +220,4 @@ class LegislationClassification(models.Model):
our_name = __class__.__name__ our_name = __class__.__name__
return reverse("{}.detail".format(our_name), kwargs={"model_id": self.id}) return reverse("{}.detail".format(our_name), kwargs={"model_id": self.id})
models_in_index = [LegislationClassification, School, Country, Sponsor] models_in_index = [LegislationClassification, School, Country, Sponsor, Category]

View File

@ -24,6 +24,8 @@
<p>The delegates above represented the <a href="/explorer/countries/{{ legislation.country.id }}">Delegation of {{ legislation.country }}</a>.</p> <p>The delegates above represented the <a href="/explorer/countries/{{ legislation.country.id }}">Delegation of {{ legislation.country }}</a>.</p>
{% endif %} {% endif %}
<p>This legislation was filed in the <a href="/explorer/categories/{{ legislation.category.id }}">{{ legislation.category }}</a> category</p>
<p>Presented as part of the <a href="/explorer/conference/{{ legislation.from_book.id }}">{{ legislation.from_book.name }}</a> conference</p> <p>Presented as part of the <a href="/explorer/conference/{{ legislation.from_book.id }}">{{ legislation.from_book.name }}</a> conference</p>
</div> </div>

View File

@ -15,8 +15,10 @@ urlpatterns = [
path("schools/<int:model_id>/", views.get_all_by_school, name="School.detail"), path("schools/<int:model_id>/", views.get_all_by_school, name="School.detail"),
path("countries/<int:model_id>/", views.get_all_by_country, name="Country.detail"), path("countries/<int:model_id>/", views.get_all_by_country, name="Country.detail"),
path("sponsors/<int:model_id>/", views.get_all_by_sponsor, name="Sponsor.detail"), path("sponsors/<int:model_id>/", views.get_all_by_sponsor, name="Sponsor.detail"),
path("categories/<int:model_id>/", views.get_all_by_category, name="Category.detail"),
path("schools/", views.get_all_schools, name="School"), path("schools/", views.get_all_schools, name="School"),
path("countries/", views.get_all_countries, name="Country"), path("countries/", views.get_all_countries, name="Country"),
path("groups/", views.return_groups, name="Groups"), path("groups/", views.return_groups, name="Groups"),
path("sponsors/", views.get_all_sponsors, name="Sponsor") path("sponsors/", views.get_all_sponsors, name="Sponsor"),
path("categories/", views.get_all_categories, name="Category"),
] ]

View File

@ -9,6 +9,7 @@ from .models import (
School, School,
Country, Country,
Sponsor, Sponsor,
Category,
models_in_index, models_in_index,
) )
@ -132,8 +133,10 @@ def return_groups(request):
get_all_by_school = get_all_by_x(School) get_all_by_school = get_all_by_x(School)
get_all_by_country = get_all_by_x(Country) get_all_by_country = get_all_by_x(Country)
get_all_by_sponsor = get_all_by_x(Sponsor) get_all_by_sponsor = get_all_by_x(Sponsor)
get_all_by_category = get_all_by_x(Category)
get_all_schools = get_all_xs(School) get_all_schools = get_all_xs(School)
get_all_countries = get_all_xs(Country) get_all_countries = get_all_xs(Country)
get_all_sponsors = get_all_xs(Sponsor) get_all_sponsors = get_all_xs(Sponsor)
get_all_categories = get_all_xs(Category)
get_all_classifications = get_all_xs(LegislationClassification) get_all_classifications = get_all_xs(LegislationClassification)