-
Notifications
You must be signed in to change notification settings - Fork 2
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
15 changed files
with
506 additions
and
0 deletions.
There are no files selected for viewing
Empty file.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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", | ||
), | ||
}, | ||
), | ||
) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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" |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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 = [] |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1 @@ | ||
from django.shortcuts import render # noqa F401 |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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", | ||
), | ||
), | ||
] |
29 changes: 29 additions & 0 deletions
29
app/logger/migrations/0028_rename_entrance_trip_entered_by_trip_exited_by.py
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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", | ||
), | ||
), | ||
] |
Oops, something went wrong.