Created new models to replicate out of and split coord app

Moved helpers and views to their respective new apps
This commit is contained in:
st01765
2026-02-05 11:18:08 +11:00
parent ad4fd19cc7
commit b695dd8054
26 changed files with 1536 additions and 10 deletions
+11 -1
View File
@@ -1,3 +1,13 @@
from django.contrib import admin
from import_export.admin import ImportExportModelAdmin
# Register your models here.
from common.models import Suburb
class MyImportExportModelAdmin(ImportExportModelAdmin):
def has_import_permission(self, request):
return request.user.is_superuser
@admin.register(Suburb)
class SuburbsAdmin(MyImportExportModelAdmin, admin.ModelAdmin):
list_filter = ["state"]
+14
View File
@@ -0,0 +1,14 @@
from io import BytesIO
from django.http import HttpResponse
from django.template.loader import get_template
from xhtml2pdf import pisa
def render_to_pdf(template, context):
html = get_template(template).render(context)
result = BytesIO()
pdf = pisa.pisaDocument(BytesIO(html.encode("ISO-8859-1")), result)
if pdf.err:
return HttpResponse("Invalid PDF", status_code=400, content_type='text/plan')
return HttpResponse(result.getvalue(), content_type='application/pdf')
+21 -1
View File
@@ -1,3 +1,23 @@
from django.db import models
# Create your models here.
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}"