Skip to content

Commit

Permalink
Initial framework
Browse files Browse the repository at this point in the history
  • Loading branch information
anorthall committed Jul 31, 2023
1 parent 66220e2 commit f58a191
Show file tree
Hide file tree
Showing 15 changed files with 506 additions and 0 deletions.
Empty file added app/caves/__init__.py
Empty file.
53 changes: 53 additions & 0 deletions app/caves/admin.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,53 @@
from django.contrib import admin
from unfold.admin import ModelAdmin, TabularInline

from .models import CaveEntrance, CaveSystem


class CaveEntranceInline(TabularInline):
model = CaveEntrance
fk_name = "system"
fields = ("name", "region", "country", "coordinates")
readonly_fields = ("coordinates",)


@admin.register(CaveSystem)
class CaveSystemAdmin(ModelAdmin):
inlines = [CaveEntranceInline]
search_fields = (
"name",
"user__username",
"user__name",
"user__email",
)
search_help_text = "Search by system name, or author name, email or username."
readonly_fields = ("added", "updated", "uuid")
list_display = (
"user",
"name",
"added",
"updated",
)
list_display_links = ("name",)
list_filter = ("added", "updated")
ordering = ("-added",)
autocomplete_fields = ("user",)
fieldsets = (
(
"Cave system",
{
"fields": ("name",),
},
),
(
"Internal data",
{
"fields": (
"user",
"uuid",
"added",
"updated",
),
},
),
)
6 changes: 6 additions & 0 deletions app/caves/apps.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
from django.apps import AppConfig


class CavesConfig(AppConfig):
default_auto_field = "django.db.models.BigAutoField"
name = "caves"
114 changes: 114 additions & 0 deletions app/caves/migrations/0001_initial.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,114 @@
# Generated by Django 4.2.3 on 2023-07-29 21:17

import uuid

import django.contrib.gis.db.models.fields
import django.db.models.deletion
import django_countries.fields
from django.conf import settings
from django.db import migrations, models


class Migration(migrations.Migration):
initial = True

dependencies = [
migrations.swappable_dependency(settings.AUTH_USER_MODEL),
]

operations = [
migrations.CreateModel(
name="CaveSystem",
fields=[
(
"id",
models.BigAutoField(
auto_created=True,
primary_key=True,
serialize=False,
verbose_name="ID",
),
),
("name", models.CharField(max_length=100)),
(
"uuid",
models.UUIDField(
default=uuid.uuid4,
editable=False,
unique=True,
verbose_name="UUID",
),
),
("added", models.DateTimeField(auto_now_add=True)),
("updated", models.DateTimeField(auto_now=True)),
(
"user",
models.ForeignKey(
on_delete=django.db.models.deletion.CASCADE,
to=settings.AUTH_USER_MODEL,
),
),
],
),
migrations.CreateModel(
name="CaveEntrance",
fields=[
(
"id",
models.BigAutoField(
auto_created=True,
primary_key=True,
serialize=False,
verbose_name="ID",
),
),
("name", models.CharField(max_length=255)),
(
"region",
models.CharField(
blank=True,
help_text="The state or region in which the cave is located.",
max_length=100,
),
),
("country", django_countries.fields.CountryField(max_length=2)),
(
"location",
models.CharField(
blank=True,
help_text="Enter a decimal latitude and longitude, address, or place name. Cave locations are not visible to other users.",
max_length=100,
),
),
(
"coordinates",
django.contrib.gis.db.models.fields.PointField(
blank=True,
geography=True,
help_text="The coordinates of the cave in WGS84 format.",
null=True,
srid=4326,
),
),
(
"uuid",
models.UUIDField(
default=uuid.uuid4,
editable=False,
unique=True,
verbose_name="UUID",
),
),
("added", models.DateTimeField(auto_now_add=True)),
("updated", models.DateTimeField(auto_now=True)),
(
"system",
models.ForeignKey(
on_delete=django.db.models.deletion.CASCADE,
related_name="entrances",
to="caves.cavesystem",
),
),
],
),
]
Empty file.
60 changes: 60 additions & 0 deletions app/caves/models.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,60 @@
import uuid as uuid

from django.contrib.gis.db import models
from django_countries.fields import CountryField


class CaveSystemManager(models.Manager):
def by(self, user):
return self.filter(user=user)


class CaveSystem(models.Model):
name = models.CharField(max_length=100)
uuid = models.UUIDField("UUID", default=uuid.uuid4, editable=False, unique=True)
added = models.DateTimeField(auto_now_add=True)
updated = models.DateTimeField(auto_now=True)
user = models.ForeignKey("users.CavingUser", on_delete=models.CASCADE)
objects = CaveSystemManager()

def __str__(self):
return self.name


class CaveEntrance(models.Model):
name = models.CharField(max_length=255)
system = models.ForeignKey(
CaveSystem, on_delete=models.CASCADE, related_name="entrances"
)
region = models.CharField(
max_length=100,
blank=True,
help_text="The state or region in which the cave is located.",
)
country = CountryField()
location = models.CharField(
max_length=100,
blank=True,
help_text=(
"Enter a decimal latitude and longitude, "
"address, or place name. "
"Cave locations are not visible to other users."
),
)
coordinates = models.PointField(
blank=True,
null=True,
geography=True,
help_text="The coordinates of the cave in WGS84 format.",
)

uuid = models.UUIDField("UUID", default=uuid.uuid4, editable=False, unique=True)
added = models.DateTimeField(auto_now_add=True)
updated = models.DateTimeField(auto_now=True)

def __str__(self):
return f"{self.name} ({self.system.name})"

@property
def user(self):
return self.system.user
Empty file added app/caves/tests/__init__.py
Empty file.
4 changes: 4 additions & 0 deletions app/caves/urls.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
from django.urls import path # noqa F401

app_name = "caves"
urlpatterns = []
1 change: 1 addition & 0 deletions app/caves/views.py
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
from django.shortcuts import render # noqa F401
34 changes: 34 additions & 0 deletions app/logger/migrations/0027_trip_entrance_trip_system.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,34 @@
# Generated by Django 4.2.3 on 2023-07-29 21:17

import django.db.models.deletion
from django.db import migrations, models


class Migration(migrations.Migration):
dependencies = [
("caves", "0001_initial"),
("logger", "0026_alter_trip_cave_location"),
]

operations = [
migrations.AddField(
model_name="trip",
name="entrance",
field=models.ForeignKey(
null=True,
on_delete=django.db.models.deletion.CASCADE,
related_name="trips",
to="caves.caveentrance",
),
),
migrations.AddField(
model_name="trip",
name="system",
field=models.ForeignKey(
null=True,
on_delete=django.db.models.deletion.CASCADE,
related_name="trips",
to="caves.cavesystem",
),
),
]
Original file line number Diff line number Diff line change
@@ -0,0 +1,29 @@
# Generated by Django 4.2.3 on 2023-07-29 21:25

import django.db.models.deletion
from django.db import migrations, models


class Migration(migrations.Migration):
dependencies = [
("caves", "0001_initial"),
("logger", "0027_trip_entrance_trip_system"),
]

operations = [
migrations.RenameField(
model_name="trip",
old_name="entrance",
new_name="entered_by",
),
migrations.AddField(
model_name="trip",
name="exited_by",
field=models.ForeignKey(
null=True,
on_delete=django.db.models.deletion.CASCADE,
related_name="exits",
to="caves.caveentrance",
),
),
]
Loading

0 comments on commit f58a191

Please sign in to comment.