Models

aploader

AP Loader leverages elex, a tool created by NPR and the New York Times, to get election results from the AP Elections API.

APElectionMeta

class aploader.models.APElectionMeta(*args, **kwargs)

Election information corresponding to AP election night.

Parameters:
  • id (AutoField) – Id
  • election (OneToOneField to Election) – Election
  • ballot_measure (OneToOneField to BallotMeasure) – Ballot measure
  • ap_election_id (CharField) – Ap election id
  • called (BooleanField) – Called
  • tabulated (BooleanField) – Tabulated
  • override_ap_call (BooleanField) – Override ap call
  • override_ap_votes (BooleanField) – Override ap votes
  • precincts_reporting (PositiveIntegerField) – Precincts reporting
  • precincts_total (PositiveIntegerField) – Precincts total
  • precincts_reporting_pct (DecimalField) – Precincts reporting pct

ChamberCall

class aploader.models.ChamberCall(*args, **kwargs)

Calls for chambers of Congress

Parameters:
  • id (AutoField) – Id
  • body (ForeignKey to Body) – Body
  • cycle (ForeignKey to ElectionCycle) – Cycle
  • party (ForeignKey to Party) – Party
  • call_time (DateTimeField) – Call time

demography

Demography collects and aggregates Census variables by the political divisions defined in Geography.

CensusEstimate

class demography.models.CensusEstimate(*args, **kwargs)

Individual census series estimates.

Parameters:
  • id (AutoField) – Id
  • division (ForeignKey to Division) – Division
  • variable (ForeignKey to CensusVariable) – Variable
  • estimate (FloatField) – Estimate

CensusLabel

class demography.models.CensusLabel(*args, **kwargs)

Custom labels for census variables that allow us to aggregate variables.

Parameters:
  • id (AutoField) – Id
  • label (CharField) – Label
  • aggregation (CharField) – Aggregation
  • table (ForeignKey to CensusTable) – Table

CensusTable

class demography.models.CensusTable(*args, **kwargs)

A census series.

Parameters:
  • id (AutoField) – Id
  • series (CharField) – Series
  • year (CharField) – Year
  • code (CharField) – Code
  • title (CharField) – Title

CensusVariable

class demography.models.CensusVariable(*args, **kwargs)

Individual variables on census series to pull, e.g., “001E” on ACS table 19001, the total for household income.

Parameters:
  • id (AutoField) – Id
  • code (CharField) – 3 digit code for variable and ‘E’, e.g., 001E.
  • table (ForeignKey to CensusTable) – Table
  • label (ForeignKey to CensusLabel) – Label

election

Election models information about races for particular offices. It also models candidate information, which inherits people from Entity and attaches them to races in Election.

BallotAnswer

class election.models.BallotAnswer(*args, **kwargs)

An answer to a ballot question.

Parameters:
  • id (UUIDField) – Id
  • label (CharField) – Label
  • short_label (CharField) – Short label
  • answer (TextField) – Answer
  • winner (BooleanField) – Winner
  • ballot_measure (ForeignKey to BallotMeasure) – Ballot measure

BallotMeasure

class election.models.BallotMeasure(*args, **kwargs)

A ballot measure.

Parameters:
  • uid (CharField) – Uid
  • label (CharField) – Label
  • short_label (CharField) – Short label
  • question (TextField) – Question
  • division (ForeignKey to Division) – Division
  • number (CharField) – Number
  • election_day (ForeignKey to ElectionDay) – Election day

Candidate

class election.models.Candidate(*args, **kwargs)

A person who runs in a race for an office.

Parameters:
  • id (UUIDField) – Id
  • uid (CharField) – Uid
  • race (ForeignKey to Race) – Race
  • person (ForeignKey to Person) – Person
  • party (ForeignKey to Party) – Party
  • ap_candidate_id (CharField) – Ap candidate id
  • incumbent (BooleanField) – Incumbent
  • top_of_ticket (ForeignKey to Candidate) – Top of ticket
  • prospective (BooleanField) – The candidate has not yet declared her candidacy.

CandidateElection

class election.models.CandidateElection(*args, **kwargs)

A CandidateElection represents the abstract relationship between a candidate and an election and carries properties like whether the candidate is uncontested or whether we aggregate their vote totals.

Parameters:
  • id (UUIDField) – Id
  • candidate (ForeignKey to Candidate) – Candidate
  • election (ForeignKey to Election) – Election
  • aggregable (BooleanField) – Aggregable
  • uncontested (BooleanField) – Uncontested

Election

class election.models.Election(*args, **kwargs)

A specific contest in a race held on a specific day.

Parameters:
  • uid (CharField) – Uid
  • election_type (ForeignKey to ElectionType) – Election type
  • race (ForeignKey to Race) – Race
  • party (ForeignKey to Party) – Party
  • election_day (ForeignKey to ElectionDay) – Election day
  • division (ForeignKey to Division) – Division
  • candidates (ManyToManyField) – Candidates

ElectionCycle

class election.models.ElectionCycle(uid, slug, name)
Parameters:
  • uid (CharField) – Uid
  • slug (SlugField) – Slug
  • name (CharField) – Name

ElectionDay

class election.models.ElectionDay(*args, **kwargs)

A day on which one or many elections can be held.

Parameters:
  • uid (CharField) – Uid
  • slug (SlugField) – Slug
  • date (DateField) – Date
  • cycle (ForeignKey to ElectionCycle) – Cycle

ElectionEvent

class election.models.ElectionEvent(*args, **kwargs)

A statewide election event

Parameters:
  • id (AutoField) – Id
  • slug (SlugField) – Slug
  • label (CharField) – Label
  • event_type (CharField) – Event type
  • dem_primary_type (CharField) – Dem primary type
  • gop_primary_type (CharField) – Gop primary type
  • election_day (ForeignKey to ElectionDay) – Election day
  • division (ForeignKey to Division) – Division
  • early_vote_start (DateField) – Early vote start
  • early_vote_close (DateField) – Early vote close
  • vote_by_mail_application_deadline (DateField) – Vote by mail application deadline
  • vote_by_mail_ballot_deadline (DateField) – Vote by mail ballot deadline
  • online_registration_deadline (DateField) – Online registration deadline
  • registration_deadline (DateField) – Registration deadline
  • poll_closing_time (DateTimeField) – Poll closing time

ElectionType

class election.models.ElectionType(*args, **kwargs)

e.g., “General”, “Primary”

Parameters:
  • uid (CharField) – Uid
  • slug (SlugField) – Slug
  • label (CharField) – Label
  • short_label (CharField) – Short label
  • ap_code (CharField) – Ap code
  • number_of_winners (PositiveSmallIntegerField) – Number of winners
  • winning_threshold (DecimalField) – Winning threshold

Race

class election.models.Race(*args, **kwargs)

A race for an office comprised of one or many elections.

Parameters:
  • uid (CharField) – Uid
  • slug (SlugField) – Slug
  • label (CharField) – Label
  • short_label (CharField) – Short label
  • description (TextField) – Description
  • office (ForeignKey to Office) – Office
  • cycle (ForeignKey to ElectionCycle) – Cycle
  • special (BooleanField) – Special

electionnight

Election Night builds live results pages based on AP data and models the text content needed on those pages.

PageContent

class electionnight.models.PageContent(*args, **kwargs)

A specific page that content can attach to.

Parameters:
  • id (UUIDField) – Id
  • content_type (ForeignKey to ContentType) – Content type
  • object_id (CharField) – Object id
  • election_day (ForeignKey to ElectionDay) – Election day
  • division (ForeignKey to Division) – Division
  • special_election (BooleanField) – Special election
  • parent (ForeignKey to PageContent) – Parent
  • featured (ManyToManyField) – Featured

PageContentBlock

class electionnight.models.PageContentBlock(*args, **kwargs)

A block of content for an individual page.

Parameters:
  • id (UUIDField) – Id
  • page (ForeignKey to PageContent) – Page
  • content_type (ForeignKey to PageContentType) – Content type
  • content (MarkdownField) – Content
  • created (DateTimeField) – Created
  • updated (DateTimeField) – Updated

PageContentType

class electionnight.models.PageContentType(*args, **kwargs)

The kind of content contained in a content block. Used to serialize content blocks.

Parameters:
  • slug (SlugField) – Slug
  • name (CharField) – Name

PageType

class electionnight.models.PageType(*args, **kwargs)

A type of page that content can attach to.

Parameters:
  • id (UUIDField) – Id
  • model_type (ForeignKey to ContentType) – Model type
  • election_day (ForeignKey to ElectionDay) – Election day
  • division_level (ForeignKey to DivisionLevel) – Set for all page types except generic election day
  • jurisdiction (ForeignKey to Jurisdiction) – Only set jurisdiction for federal pages
  • body (ForeignKey to Body) – Only set body for senate/house pages
  • office (ForeignKey to Office) – Only set office for the presidency

entity

Entity houses models for people and organizations. For example, the Republican Party is an organization, and Mitt Romney is a person. Their roles as political parties and candidates will come in downstream apps, but Entity houses the base level information about them.

ImageTag

class entity.models.ImageTag(*args, **kwargs)

Tags represent a type of image, which is used to serialize it.

Parameters:
  • id (AutoField) – Id
  • name (SlugField) – Name

Organization

class entity.models.Organization(*args, **kwargs)

An org.

Generally follows the Popolo spec: http://www.popoloproject.com/specs/organization.html

Parameters:
  • id (UUIDField) – Id
  • uid (CharField) – Uid
  • slug (SlugField) – Slug
  • name (CharField) – Name
  • identifiers (JSONField) – Identifiers
  • classification (ForeignKey to OrganizationClassification) – Classification
  • parent (ForeignKey to Organization) – Parent
  • national_headquarters (CountryField) – National headquarters
  • founding_date (DateField) – Founding date
  • dissolution_date (DateField) – Dissolution date
  • summary (CharField) – A one-line biographical summary.
  • description (TextField) – A longer-form description.
  • links (ArrayField) – External web links, comma-separated.
  • created (DateTimeField) – Created
  • updated (DateTimeField) – Updated

OrganizationClassification

class entity.models.OrganizationClassification(id, name)
Parameters:
  • id (AutoField) – Id
  • name (CharField) – Name

OrganizationImage

class entity.models.OrganizationImage(*args, **kwargs)

Image attached to a person, which can be serialized by a tag.

Parameters:
  • id (AutoField) – Id
  • organization (ForeignKey to Organization) – Organization
  • tag (ForeignKey to ImageTag) – Used to serialize images.
  • image (ImageField) – Image
  • created (DateTimeField) – Created
  • updated (DateTimeField) – Updated

Person

class entity.models.Person(*args, **kwargs)

A real human being.🎵

Generally follows the Popolo spec: http://www.popoloproject.com/specs/person.html

Parameters:
  • id (UUIDField) – Id
  • uid (CharField) – Uid
  • slug (SlugField) – Slug
  • last_name (CharField) – Last name
  • first_name (CharField) – First name
  • middle_name (CharField) – Middle name
  • suffix (CharField) – Suffix
  • full_name (CharField) – Full name
  • identifiers (JSONField) – Identifiers
  • gender (GenderField) – Gender
  • race (RaceField) – Race
  • nationality (CountryField) – Nationality
  • state_of_residence (StateField) – If U.S. resident.
  • birth_date (DateField) – Birth date
  • death_date (DateField) – Death date
  • summary (CharField) – A one-line biographical summary.
  • description (TextField) – A longer-form description.
  • links (ArrayField) – External web links, comma-separated.
  • created (DateTimeField) – Created
  • updated (DateTimeField) – Updated

PersonImage

class entity.models.PersonImage(*args, **kwargs)

Image attached to a person, which can be serialized by a tag.

Parameters:
  • id (AutoField) – Id
  • person (ForeignKey to Person) – Person
  • tag (ForeignKey to ImageTag) – Used to serialize images.
  • image (ImageField) – Image
  • created (DateTimeField) – Created
  • updated (DateTimeField) – Updated

geography

Geography houses models for all of the geographic political divisions in the United States. It contains bootstrap scripts that get shapefiles from the Census Bureau for states, counties and congressional districts and load them into your database. It also creates a simplified geography for each of those objects.

Division

class geography.models.Division(*args, **kwargs)

A political or administrative geography.

For example, a particular state, county, district, precinct or municipality.

Parameters:
  • id (UUIDField) – Id
  • uid (CharField) – Uid
  • slug (SlugField) – Slug
  • name (CharField) – Name
  • label (CharField) – Label
  • short_label (CharField) – Short label
  • parent (ForeignKey to Division) – Parent
  • level (ForeignKey to DivisionLevel) – Level
  • code (CharField) – Code representing a geography: FIPS code for states and counties, district number for districts, precinct number for precincts, etc.
  • code_components (JSONField) – Component parts of code
  • effective (BooleanField) – Effective
  • effective_start (DateTimeField) – Effective start
  • effective_end (DateTimeField) – Effective end
  • intersecting (ManyToManyField) – Intersecting divisions intersect this one geographically but do not necessarily have a parent/child relationship. The relationship between a congressional district and a precinct is an example of an intersecting relationship.

DivisionLevel

class geography.models.DivisionLevel(*args, **kwargs)

Level of government or administration at which a division exists.

For example, federal, state, district, county, precinct, municipal.

Parameters:
  • id (UUIDField) – Id
  • uid (CharField) – Uid
  • slug (SlugField) – Slug
  • name (CharField) – Name
  • parent (ForeignKey to DivisionLevel) – Parent

Geometry

class geography.models.Geometry(*args, **kwargs)

The spatial representation (in topoJSON) of a Division.

Parameters:
  • id (UUIDField) – Id
  • division (ForeignKey to Division) – Division
  • subdivision_level (ForeignKey to DivisionLevel) – Subdivision level
  • simplification (FloatField) – Minimum quantile of planar triangle areas for simplfying topojson.
  • topojson (JSONField) – Topojson
  • source (URLField) – Link to the source of this geography data.
  • series (CharField) – Year of boundary series, e.g., 2016 TIGER/Line files.
  • effective (BooleanField) – Effective
  • effective_start (DateField) – Effective start
  • effective_end (DateField) – Effective end

IntersectRelationship

class geography.models.IntersectRelationship(*args, **kwargs)

Each IntersectRelationship instance represents one side of a paired relationship between intersecting divisions.

The intersection field represents the decimal proportion of the to_division that intersects with the from_division. It’s useful for apportioning counts between the areas, for example, population statistics from census data.

Parameters:
  • id (AutoField) – Id
  • from_division (ForeignKey to Division) – From division
  • to_division (ForeignKey to Division) – To division
  • intersection (DecimalField) – The portion of the to_division that intersects this division.

government

Government contains information about political jurisdictions, bodies, and offices. For example, the United States Federal Government is a jurisdiction, the U.S. Senate is a body, and the Class 1 Senate seat from Texas is an office. It also contains the modeling for political parties.

Body

class government.models.Body(*args, **kwargs)

A body represents a collection of offices or individuals organized around a common government or public service function.

For example: the U.S. Senate, Florida House of Representatives, Columbia City Council, etc.

Note

Duplicate slugs are allowed on this model to accomodate states, for example:

  • florida/senate/
  • michigan/senate/
Parameters:
  • id (UUIDField) – Id
  • uid (CharField) – Uid
  • slug (SlugField) – Customizable slug. Defaults to Org slug without stopwords.
  • label (CharField) – Label
  • short_label (CharField) – Short label
  • organization (OneToOneField to Organization) – Organization
  • jurisdiction (ForeignKey to Jurisdiction) – Jurisdiction
  • parent (ForeignKey to Body) – Parent

Jurisdiction

class government.models.Jurisdiction(*args, **kwargs)

A Jurisdiction represents a logical unit of governance, comprised of a collection of legislative bodies, administrative offices or public services.

For example: the United States Federal Government, the Government of the District of Columbia, Columbia Missouri City Government, etc.

Parameters:
  • id (UUIDField) – Id
  • uid (CharField) – Uid
  • slug (SlugField) – Slug
  • name (CharField) – Name
  • division (ForeignKey to Division) – Division
  • parent (ForeignKey to Jurisdiction) – Parent

Office

class government.models.Office(*args, **kwargs)

An office represents a post, seat or position occuppied by an individual as a result of an election.

For example: Senator, Governor, President, Representative.

In the case of executive positions, like governor or president, the office is tied directlty to a jurisdiction. Otherwise, the office ties to a body tied to a jurisdiction.

Note

Duplicate slugs are allowed on this model to accomodate states, for example:

  • florida/house/seat-2/
  • michigan/house/seat-2/
Parameters:
  • id (UUIDField) – Id
  • uid (CharField) – Uid
  • slug (SlugField) – Slug
  • name (CharField) – Name
  • label (CharField) – Label
  • short_label (CharField) – Short label
  • senate_class (CharField) – Senate class
  • division (ForeignKey to Division) – Division
  • jurisdiction (ForeignKey to Jurisdiction) – Jurisdiction
  • body (ForeignKey to Body) – Body

Party

class government.models.Party(*args, **kwargs)

A political party.

Parameters:
  • id (UUIDField) – Id
  • uid (CharField) – Uid
  • slug (SlugField) – Customizable slug. Defaults to slugged Org name.
  • label (CharField) – Label
  • short_label (CharField) – Short label
  • organization (OneToOneField to Organization) – All parties except Independent should attach to an Org.
  • ap_code (CharField) – Ap code
  • aggregate_candidates (BooleanField) – Determines whether to globally aggregate vote totals of this party’s candidates during an election.

vote

Vote models various types of voting that happens in elections.

Delegates

class vote.models.Delegates(*args, **kwargs)

Pledged delegates.

Parameters:
  • id (UUIDField) – Id
  • division (ForeignKey to Division) – Division
  • count (PositiveIntegerField) – Count
  • pct (DecimalField) – Pct
  • total (PositiveIntegerField) – Total
  • candidate_election (ForeignKey to CandidateElection) – Candidate election
  • superdelegates (BooleanField) – Superdelegates

ElectoralVotes

class vote.models.ElectoralVotes(*args, **kwargs)

Electoral votes.

Parameters:
  • id (UUIDField) – Id
  • division (ForeignKey to Division) – Division
  • count (PositiveIntegerField) – Count
  • pct (DecimalField) – Pct
  • total (PositiveIntegerField) – Total
  • candidate_election (ForeignKey to CandidateElection) – Candidate election
  • winning (BooleanField) – Winning

Votes

class vote.models.Votes(*args, **kwargs)

Popular votes.

Parameters:
  • id (UUIDField) – Id
  • division (ForeignKey to Division) – Division
  • count (PositiveIntegerField) – Count
  • pct (DecimalField) – Pct
  • total (PositiveIntegerField) – Total
  • candidate_election (ForeignKey to CandidateElection) – Candidate election
  • ballot_answer (ForeignKey to BallotAnswer) – Ballot answer
  • winning (BooleanField) – Winning
  • runoff (BooleanField) – Runoff