Files
bus-manager/busManager/locations/models.py
T
st01765 4025c28eae Added locations app
Moved contacts to new model
2026-02-26 13:34:32 +11:00

35 lines
1.1 KiB
Python

from django.db import models
class Suburb(models.Model):
STATE = [
("VIC", "Victoria"),
("NSW", "New South Wales"),
("SA", "South Australia"),
("ACT", "Australia Capital Territory"),
("QLD", "Queensland"),
("NT", "Northern Territory"),
("WA", "Western Australia"),
("TAS", "Tasmania"),
]
name = models.CharField(max_length=30, unique=True)
state = models.CharField(max_length=3, choices=STATE)
postcode = models.PositiveSmallIntegerField()
distance = models.PositiveSmallIntegerField(blank=True, null=True)
class Meta:
ordering = ["name"]
def __str__(self):
return f"{self.name}, {self.state} {self.postcode}"
class Location(models.Model):
address = models.CharField(max_length=255, blank=True)
suburb = models.ForeignKey(Suburb, on_delete=models.PROTECT)
latitude = models.FloatField(null=True, blank=True)
longitude = models.FloatField(null=True, blank=True)
class Meta: unique_together = ("suburb", "address")
def __str__(self):
return f"{self.address}, {self.suburb}"