For the complete documentation index, see llms.txt. This page is also available as Markdown.

Townships

Administrative endpoints for townships — the sub-city geographic units used as the third level of the address hierarchy (Country → City → Township → District).

A township belongs to a single city and consists of a display name, an active/inactive status, an optional post/zip code, and optional multilingual translations of the name.

Core Capabilities

1. Township Listing & Filtering

  • Retrieve a paginated list of all townships (active and inactive), ordered by name ascending.

  • Filter by city, country, name (exact or starts-with prefix), presence of a retail store, retail store type, or a set of identifiers (pk__in).

  • Order results with the sort parameter.

2. Township Lifecycle Management

  • Create a township under a city with a unique name within that city.

  • Fully or partially update an existing township, including its translations.

  • Deactivate a township (soft delete — sets is_active to false; the record is not removed).

3. Multilingual Names

  • Store translated names under the translations field, keyed by language code.

Township Fields

Field
Type
Description

pk

integer

The unique identifier of the township. Assigned by the server; read-only.

is_active

boolean

Whether the township is active.

name

string (max 128 chars)

The display name of the township. Required on create and full update.

city

integer

The identifier of the city this township belongs to. Required on create and full update.

postcode

string or null

The post/zip code associated with the township. Optional.

translations

object or null

A mapping of language codes to translated field values. Example: {"tr": {"name": "Kadıköy"}}. Optional; defaults to {}.

Filtering & Ordering

Parameter
Match
Notes

name

Case-insensitive contains

?name=kad matches Kadıköy.

city

Exact (integer)

Keeps only townships belonging to the given city id.

country

Exact (integer)

Keeps only townships belonging to cities in the given country id.

name_startswith

Case-insensitive prefix

?name_startswith=kad matches Kadıköy.

pk__in

Comma-separated integers

E.g. ?pk__in=1,2,3. Returns only the townships whose pk is in the list.

retailstore__isnull

Boolean

false keeps only townships that have at least one retail store; true keeps only townships with no retail store.

store_type

Exact, case-sensitive

Keeps only townships whose retail stores have the given store type name.

Results are ordered by name ascending by default. Use the sort query parameter to change the order; prefix with - for descending (e.g. ?sort=-pk).

Validation Rules

  • name and city are required on create and full update.

  • The combination of city and name must be unique at the application layer (there is no database-level unique constraint). A duplicate is rejected with 406 Not Acceptable carrying {"non_field_errors": "<message>", "error_code": "<code>"}. This check applies to create (POST) and update (PUT/PATCH).

Soft Delete

Calling DELETE /townships/{id}/ does not remove the record from the database. It sets is_active to false. The record can be reactivated at any time with PATCH /townships/{id}/ sending {"is_active": true}.

Dynamic Settings & Environment Variables

No dynamic settings (dj_dynamic_settings) are read directly by the township endpoints. Listing, create, update, and deactivate operations behave identically regardless of management panel configuration.

The DEFAULT_COUNTRY_CODE dynamic setting — registered in omnishop/address/settings/conf.py — identifies which country is used as the default in address forms and checkout flows, but it is consumed by the address and checkout services, not by these administrative endpoints.

Environment variables: No environment variables are read directly by these endpoints.

Last updated

Was this helpful?