Added locations app
Moved contacts to new model
This commit is contained in:
@@ -0,0 +1,13 @@
|
||||
from django.contrib import admin
|
||||
|
||||
from common.admin import MyImportExportModelAdmin
|
||||
from locations.models import Suburb, Location
|
||||
|
||||
|
||||
@admin.register(Suburb)
|
||||
class SuburbsAdmin(MyImportExportModelAdmin, admin.ModelAdmin):
|
||||
list_filter = ["state"]
|
||||
|
||||
@admin.register(Location)
|
||||
class LocationAdmin(admin.ModelAdmin):
|
||||
search_fields = ["address", "suburb__name", "suburb__postcode"]
|
||||
@@ -0,0 +1,6 @@
|
||||
from django.apps import AppConfig
|
||||
|
||||
|
||||
class LocationsConfig(AppConfig):
|
||||
default_auto_field = 'django.db.models.BigAutoField'
|
||||
name = 'locations'
|
||||
@@ -0,0 +1,35 @@
|
||||
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}"
|
||||
@@ -0,0 +1,3 @@
|
||||
from django.test import TestCase
|
||||
|
||||
# Create your tests here.
|
||||
@@ -0,0 +1,3 @@
|
||||
from django.shortcuts import render
|
||||
|
||||
# Create your views here.
|
||||
Reference in New Issue
Block a user