From bba89e4c7d9b466ea5bfe087de86afdffc82d6b7 Mon Sep 17 00:00:00 2001 From: James Gordon Date: Wed, 21 Jun 2017 19:44:13 -0500 Subject: [PATCH] More concise related names, update initial migration --- .../elections/migrations/0001_initial.py | 18 +++++++++--------- .../elections/models/contests/base.py | 6 +++--- 2 files changed, 12 insertions(+), 12 deletions(-) diff --git a/opencivicdata/elections/migrations/0001_initial.py b/opencivicdata/elections/migrations/0001_initial.py index 76dcc96..33a5837 100644 --- a/opencivicdata/elections/migrations/0001_initial.py +++ b/opencivicdata/elections/migrations/0001_initial.py @@ -1,5 +1,5 @@ # -*- coding: utf-8 -*- -# Generated by Django 1.11.2 on 2017-06-05 19:54 +# Generated by Django 1.11.2 on 2017-06-22 00:43 from __future__ import unicode_literals import django.contrib.postgres.fields @@ -33,7 +33,7 @@ class Migration(migrations.Migration): ('description', models.TextField(help_text='Text describing the purpose and/or potential outcomes of the ballot measure, not necessarily as it appears on the ballot.')), ('requirement', models.CharField(blank=True, default='50% plus one vote', help_text='The threshold of votes the ballot measure needs in order to pass.', max_length=300)), ('classification', models.CharField(blank=True, help_text='Describes the origin and/or potential outcome of the ballot measure, e.g., "initiative statute", "legislative constitutional amendment".', max_length=300)), - ('division', models.ForeignKey(help_text="Reference to the Division that defines the political geography of the contest, e.g., a specific Congressional or State Senate district. Should be a subdivision of the Division referenced by the contest's Election.", on_delete=django.db.models.deletion.CASCADE, related_name='ballotmeasurecontest_divisions', related_query_name='ballotmeasurecontests', to='core.Division')), + ('division', models.ForeignKey(help_text="Reference to the Division that defines the political geography of the contest, e.g., a specific Congressional or State Senate district. Should be a subdivision of the Division referenced by the contest's Election.", on_delete=django.db.models.deletion.CASCADE, related_name='ballotmeasurecontests', related_query_name='ballotmeasurecontests', to='core.Division')), ], options={ 'db_table': 'opencivicdata_ballotmeasurecontest', @@ -116,7 +116,7 @@ class Migration(migrations.Migration): ('name', models.CharField(help_text='Name of the contest, not necessarily as it appears on the ballot.', max_length=300)), ('previous_term_unexpired', models.BooleanField(default=False, help_text='Indicates the previous public office holder vacated the post before serving a full term.')), ('number_elected', models.IntegerField(default=1, help_text="Number of candidates that are elected in the contest, i.e. 'N' of N-of-M.")), - ('division', models.ForeignKey(help_text="Reference to the Division that defines the political geography of the contest, e.g., a specific Congressional or State Senate district. Should be a subdivision of the Division referenced by the contest's Election.", on_delete=django.db.models.deletion.CASCADE, related_name='candidatecontest_divisions', related_query_name='candidatecontests', to='core.Division')), + ('division', models.ForeignKey(help_text="Reference to the Division that defines the political geography of the contest, e.g., a specific Congressional or State Senate district. Should be a subdivision of the Division referenced by the contest's Election.", on_delete=django.db.models.deletion.CASCADE, related_name='candidatecontests', related_query_name='candidatecontests', to='core.Division')), ], options={ 'db_table': 'opencivicdata_candidatecontest', @@ -210,8 +210,8 @@ class Migration(migrations.Migration): ('locked_fields', django.contrib.postgres.fields.ArrayField(base_field=models.TextField(), blank=True, default=list, size=None)), ('id', opencivicdata.core.models.base.OCDIDField(help_text='Open Civic Data-style id in the format ``ocd-contest/{{uuid}}``.', ocd_type='contest', serialize=False, validators=[django.core.validators.RegexValidator(flags=re.RegexFlag(32), message='ID must match ^ocd-contest/[0-9a-f]{8}-([0-9a-f]{4}-){3}[0-9a-f]{12}$', regex='^ocd-contest/[0-9a-f]{8}-([0-9a-f]{4}-){3}[0-9a-f]{12}$')])), ('name', models.CharField(help_text='Name of the contest, not necessarily as it appears on the ballot.', max_length=300)), - ('division', models.ForeignKey(help_text="Reference to the Division that defines the political geography of the contest, e.g., a specific Congressional or State Senate district. Should be a subdivision of the Division referenced by the contest's Election.", on_delete=django.db.models.deletion.CASCADE, related_name='partycontest_divisions', related_query_name='partycontests', to='core.Division')), - ('election', models.ForeignKey(help_text='Reference to the Election in which the contest is decided.', on_delete=django.db.models.deletion.CASCADE, related_name='elections_partycontest_contests', related_query_name='elections_partycontests', to='elections.Election')), + ('division', models.ForeignKey(help_text="Reference to the Division that defines the political geography of the contest, e.g., a specific Congressional or State Senate district. Should be a subdivision of the Division referenced by the contest's Election.", on_delete=django.db.models.deletion.CASCADE, related_name='partycontests', related_query_name='partycontests', to='core.Division')), + ('election', models.ForeignKey(help_text='Reference to the Election in which the contest is decided.', on_delete=django.db.models.deletion.CASCADE, related_name='partycontests', related_query_name='partycontests', to='elections.Election')), ('runoff_for_contest', models.OneToOneField(help_text='If this contest is a runoff to determine the outcome of a previously undecided contest, reference to that PartyContest.', null=True, on_delete=django.db.models.deletion.CASCADE, to='elections.PartyContest')), ], options={ @@ -266,8 +266,8 @@ class Migration(migrations.Migration): ('name', models.CharField(help_text='Name of the contest, not necessarily as it appears on the ballot.', max_length=300)), ('description', models.TextField(help_text='Text describing the purpose and/or potential outcomes of the contest, not necessarily as it appears on the ballot.')), ('requirement', models.CharField(blank=True, default='50% plus one vote', help_text='The threshold of votes need in order to retain the officeholder.', max_length=300)), - ('division', models.ForeignKey(help_text="Reference to the Division that defines the political geography of the contest, e.g., a specific Congressional or State Senate district. Should be a subdivision of the Division referenced by the contest's Election.", on_delete=django.db.models.deletion.CASCADE, related_name='retentioncontest_divisions', related_query_name='retentioncontests', to='core.Division')), - ('election', models.ForeignKey(help_text='Reference to the Election in which the contest is decided.', on_delete=django.db.models.deletion.CASCADE, related_name='elections_retentioncontest_contests', related_query_name='elections_retentioncontests', to='elections.Election')), + ('division', models.ForeignKey(help_text="Reference to the Division that defines the political geography of the contest, e.g., a specific Congressional or State Senate district. Should be a subdivision of the Division referenced by the contest's Election.", on_delete=django.db.models.deletion.CASCADE, related_name='retentioncontests', related_query_name='retentioncontests', to='core.Division')), + ('election', models.ForeignKey(help_text='Reference to the Election in which the contest is decided.', on_delete=django.db.models.deletion.CASCADE, related_name='retentioncontests', related_query_name='retentioncontests', to='elections.Election')), ('membership', models.ForeignKey(help_text='Reference to the Membership that represents the tenure of a person in a specific public office.', on_delete=django.db.models.deletion.CASCADE, to='core.Membership')), ('runoff_for_contest', models.OneToOneField(help_text='If this contest is a runoff to determine the outcome of a previously undecided contest, reference to that RetentionContest.', null=True, on_delete=django.db.models.deletion.CASCADE, related_name='runoff_contest', to='elections.RetentionContest')), ], @@ -313,7 +313,7 @@ class Migration(migrations.Migration): migrations.AddField( model_name='candidatecontest', name='election', - field=models.ForeignKey(help_text='Reference to the Election in which the contest is decided.', on_delete=django.db.models.deletion.CASCADE, related_name='elections_candidatecontest_contests', related_query_name='elections_candidatecontests', to='elections.Election'), + field=models.ForeignKey(help_text='Reference to the Election in which the contest is decided.', on_delete=django.db.models.deletion.CASCADE, related_name='candidatecontests', related_query_name='candidatecontests', to='elections.Election'), ), migrations.AddField( model_name='candidatecontest', @@ -353,7 +353,7 @@ class Migration(migrations.Migration): migrations.AddField( model_name='ballotmeasurecontest', name='election', - field=models.ForeignKey(help_text='Reference to the Election in which the contest is decided.', on_delete=django.db.models.deletion.CASCADE, related_name='elections_ballotmeasurecontest_contests', related_query_name='elections_ballotmeasurecontests', to='elections.Election'), + field=models.ForeignKey(help_text='Reference to the Election in which the contest is decided.', on_delete=django.db.models.deletion.CASCADE, related_name='ballotmeasurecontests', related_query_name='ballotmeasurecontests', to='elections.Election'), ), migrations.AddField( model_name='ballotmeasurecontest', diff --git a/opencivicdata/elections/models/contests/base.py b/opencivicdata/elections/models/contests/base.py index cf2aabf..3ae6f3e 100644 --- a/opencivicdata/elections/models/contests/base.py +++ b/opencivicdata/elections/models/contests/base.py @@ -29,7 +29,7 @@ class ContestBase(OCDBase): ) division = models.ForeignKey( Division, - related_name="%(class)s_divisions", + related_name="%(class)ss", related_query_name="%(class)ss", help_text="Reference to the Division that defines the political " "geography of the contest, e.g., a specific Congressional or " @@ -38,8 +38,8 @@ class ContestBase(OCDBase): ) election = models.ForeignKey( Election, - related_name="%(app_label)s_%(class)s_contests", - related_query_name="%(app_label)s_%(class)ss", + related_name="%(class)ss", + related_query_name="%(class)ss", help_text="Reference to the Election in which the contest is decided.", )