Models

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

A model that represents a Country object.

name

The full name of the country.

Type:

str

abbr

The country’s 3-letter abbreviation.

Type:

str

date_created

The date when the object instance was created. Inherited from TimeStampMixin.

Type:

datetime

date_modified

The date when the object instance was last modified. Inherited from TimeStampMixin.

Type:

datetime

__str__()

Returns a string representation of a Country object instance.

Returns:

A string that refers to a Country object instance.

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

A model that represents a State object.

country

The country to which the state belongs.

Type:

Country

name

The full name of the state.

Type:

str

abbr

The state’s abbreviation (should be 2 letters).

Type:

str

date_created

The date when the object instance was created. Inherited from TimeStampMixin.

Type:

datetime

date_modified

The date when the object instance was last modified. Inherited from TimeStampMixin.

Type:

datetime

__str__()

Returns a string representation of a State object instance.

Returns:

A string that refers to a State object instance.

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

A model that represents a County object.

state

The state to which the county belongs.

Type:

State

name

The full name of the county.

Type:

str

date_created

The date when the object instance was created. Inherited from TimeStampMixin.

Type:

datetime

date_modified

The date when the object instance was last modified. Inherited from TimeStampMixin.

Type:

datetime

abbr

The county’s abbreviation (‘Co.’, ‘Par.’, or ‘Boro.’).

Most states in the US are broken up into smaller units called counties, but some states call their smaller divisions parishes (Louisiana) or boroughs (Alaska).

For the purposes of this application, all of the smaller units, regardless of state, will be classified as County objects. If the instance of a County object belongs to either the state of Louisiana or Alaska, then the correct abbreviation (‘Par.’ or ‘Boro.’) will be used instead of the default ‘Co.’.

Note: Some Alaskan areas are subdivided into census areas instead of boroughs. For those units, no abbreviation will be generated.

county_line

The county’s border (if two counties are listed within the name field).

There are cases when a specimen may have been collected on the border between two counties (on the county line). This needs to be included on the specimen label by indicating the word ‘line’.

full_name

A county’s full name.

It is formatted as the county’s name, abbreviation (if it has one), and the word “line” (if there are two counties listed in the name).

__str__()

Returns a string representation of a County object instance.

It uses both a property of the County object (full_name) as well as the state abbreviation to which this County object instance belongs (state.abbr). For example, if the county is Switzerland and the state is Indiana, __str__() will return “Switzerland Co., IN”.

Returns:

A string that refers to a County object instance.

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

A model that represents a Locality object.

This class contains validation in the Wagtail admin to prevent a user from adding multiple regions to the locality. This is a personal preference for how I want the data to be structured.

For example, a locality can belong to a county but not to both a county and a state (because the county already belongs to a state). Likewise, a locality can belong to a state (if the county is unknown) but not to both a state and a country (because the state already belongs to a country).

Note: All of the fields are optional, as every location will not make use of every field available.

country

The country to which the locality belongs.

Type:

Country

state

The state to which the locality belongs.

Type:

State

county

The county to which the locality belongs.

Type:

County

name

The name of the locality.

Type:

str

range

The distance and direction of the locality from the nearest town.

Type:

str

town

The nearest town to the locality.

Type:

str

date_created

The date when the object instance was created. Inherited from TimeStampMixin.

Type:

datetime

date_modified

The date when the object instance was last modified. Inherited from TimeStampMixin.

Type:

datetime

__str__()

Returns a string representation of a Locality object instance.

Because each field for a Locality object instance is optional, each field must be first checked to see if it is null. If not null, then it is included as part of the string returned. Else, an empty string is returned in the empty field’s place.

The way this string representation is structured may be a little complex, but it is my personal preference to have as much detail as possible when looking through a list of localities. I want to be able to see the main fields (name, range, and town) if they are not null, and I’d also like to see to which county, state, or country the locality belongs.

Returns:

A string that refers to a Locality object instance.

clean()

Modifies the default Django clean() method to include some custom validation.

Because I don’t want a locality to belong to more than one region (whether that be county, state, or country), a ValidationError will be raised if two or more regions are selected for a given Locality object instance.

Raises:

Either 2 or 3 validation errors for the county, state, and country fields.

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

A model that represents a GPS object.

Note: The latitude and longitude fields are optional, as there are cases where elevation or a range of elevations are known, but GPS coordinates were not taken.

locality

The locality to which the GPS object instance belongs.

Type:

Locality

latitude

The latitude part of the GPS coordinates. It is a string rather than a float so that I have control on the exact number of decimal points when the field is serialized.

Type:

str

longitude

The longitude part of the GPS coordinates. It is a string rather than a float so that I have control on the exact number of decimal points when the field is serialized.

Type:

str

elevation

The elevation of the GPS coordinates. It is a string rather than an integer because there are some cases where a range of elevations are provided.

Type:

str

date_created

The date when the object instance was created. Inherited from TimeStampMixin.

Type:

datetime

date_modified

The date when the object instance was last modified. Inherited from TimeStampMixin.

Type:

datetime

__str__()

Returns a string representation of a GPS object instance.

Because the latitude and longitude fields are optional, each must be checked to see if it is null. If not null, then it is included as part of the string returned. Else, an empty string is returned in the empty field’s place.

Also included are the GPS object instance’s elevation and its locality for easier selection in the Wagtail admin.

Returns:

A string that refers to a GPS object instance.

elevation_meters

Adds an “m” (meters) at the end of the elevation field.

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

A model that represents a CollectingTrip object.

name

The name of the collecting trip.

Type:

str

states

A list of State object instances to which the collecting trip belongs.

Type:

State[]

start_date

The start date of the trip.

Type:

date

end_date

The end date of the trip.

Type:

date

notes

A rich text field for documenting trip notes.

Type:

str

date_created

The date when the object instance was created. Inherited from TimeStampMixin.

Type:

datetime

date_modified

The date when the object instance was last modified. Inherited from TimeStampMixin.

Type:

datetime

__str__()

Returns a string representation of a CollectingTrip object instance.

Returns:

A string that refers to a CollectingTrip object instance.

slug

Slugifies the name of a CollectingTrip object instance.