to squash

This commit is contained in:
stupidcomputer 2024-07-24 00:13:30 -05:00
parent 25415a099f
commit 2a6e42da9c
6 changed files with 24 additions and 6 deletions

View File

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

View File

@ -106,7 +106,7 @@ class LegislationBook(models.Model):
text["country"] = InstantiateIfNone(Country, text["country"]) text["country"] = InstantiateIfNone(Country, text["country"])
sponsors = text["sponsors"].split(', ') sponsors = text["sponsors"].split(', ')
sponsors = [InstantiateIfNone(Sponsor, i) for i in sponsors] sponsors = [InstantiateIfNone(Sponsor, sponsor) for sponsor in sponsors]
del text["sponsors"] del text["sponsors"]
@ -114,7 +114,7 @@ class LegislationBook(models.Model):
text.save() text.save()
for sponsor in sponsors: for sponsor in sponsors:
text.upgraded_sponsors.add(sponsor) text.sponsors.add(sponsor)
def __str__(self): def __str__(self):
return "{}".format(self.name) return "{}".format(self.name)
@ -149,7 +149,7 @@ class LegislativeText(models.Model):
category = models.CharField(max_length=256) category = models.CharField(max_length=256)
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) sponsors = models.ManyToManyField(Sponsor, blank=True)
from_book = models.ForeignKey(LegislationBook, on_delete=models.CASCADE) from_book = models.ForeignKey(LegislationBook, on_delete=models.CASCADE)
legislation_title = models.CharField(max_length=512) legislation_title = models.CharField(max_length=512)
country = models.ForeignKey(Country, on_delete=models.CASCADE, null=True) country = models.ForeignKey(Country, on_delete=models.CASCADE, null=True)

View File

@ -10,6 +10,7 @@
<li><a href="/explorer/countries/">By country</a></li> <li><a href="/explorer/countries/">By country</a></li>
<li><a href="/explorer/schools/">By school</a></li> <li><a href="/explorer/schools/">By school</a></li>
<li><a href="/explorer/topics/">By topic</a></li> <li><a href="/explorer/topics/">By topic</a></li>
<li><a href="/explorer/sponsors/">By sponsor</a></li>
</ul> </ul>
</div> </div>
{% endblock content %} {% endblock content %}

View File

@ -13,7 +13,12 @@
<p><i>{{ legislation.assembly }}/{{ legislation.committee }}/{{ legislation.docket_order }}</i></p> <p><i>{{ legislation.assembly }}/{{ legislation.committee }}/{{ legislation.docket_order }}</i></p>
<p>Sponsored by {{ legislation.sponsors }} of <a href="/explorer/schools/{{ legislation.school.id }}">{{ legislation.school }}</a></p> <p>Sponsored by
{% for sponsor in legislation.sponsors.all %}
<a href="/explorer/sponsors/{{ sponsor.id }}">{{ sponsor.name }}</a>{% if not forloop.last %}, {% endif %}
{% endfor %}
of <a href="/explorer/schools/{{ legislation.school.id }}">{{ legislation.school }}</a></p>
{% if legislation.country %} {% if legislation.country %}
<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>

View File

@ -14,7 +14,9 @@ urlpatterns = [
# these are named weirdly -- see models.py School and Country definitions # these are named weirdly -- see models.py School and Country definitions
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("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="Sponsors")
] ]

View File

@ -1,7 +1,14 @@
from django.shortcuts import get_object_or_404, render from django.shortcuts import get_object_or_404, render
from django.http import HttpResponse from django.http import HttpResponse
from .models import LegislativeText, LegislationBook, LegislationClassification, School, Country from .models import (
LegislativeText,
LegislationBook,
LegislationClassification,
School,
Country,
Sponsor
)
from random import sample from random import sample
@ -112,7 +119,9 @@ 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_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_classifications = get_all_xs(LegislationClassification) get_all_classifications = get_all_xs(LegislationClassification)