mirror of
https://github.com/seanmorley15/AdventureLog.git
synced 2025-07-24 15:29:36 +02:00
migration to new backend
This commit is contained in:
parent
28a5d423c2
commit
9abe9fb315
309 changed files with 21476 additions and 24132 deletions
59
backend/server/worldtravel/models.py
Normal file
59
backend/server/worldtravel/models.py
Normal file
|
@ -0,0 +1,59 @@
|
|||
from django.db import models
|
||||
from django.contrib.auth import get_user_model
|
||||
|
||||
|
||||
User = get_user_model()
|
||||
|
||||
default_user_id = 1 # Replace with an actual user ID
|
||||
|
||||
class Country(models.Model):
|
||||
AFRICA = 'AF'
|
||||
ANTARCTICA = 'AN'
|
||||
ASIA = 'AS'
|
||||
EUROPE = 'EU'
|
||||
NORTH_AMERICA = 'NA'
|
||||
OCEANIA = 'OC'
|
||||
SOUTH_AMERICA = 'SA'
|
||||
|
||||
CONTINENT_CHOICES = [
|
||||
(AFRICA, 'Africa'),
|
||||
(ANTARCTICA, 'Antarctica'),
|
||||
(ASIA, 'Asia'),
|
||||
(EUROPE, 'Europe'),
|
||||
(NORTH_AMERICA, 'North America'),
|
||||
(OCEANIA, 'Oceania'),
|
||||
(SOUTH_AMERICA, 'South America'),
|
||||
]
|
||||
|
||||
id = models.AutoField(primary_key=True)
|
||||
name = models.CharField(max_length=100)
|
||||
country_code = models.CharField(max_length=2)
|
||||
continent = models.CharField(
|
||||
max_length=2,
|
||||
choices=CONTINENT_CHOICES,
|
||||
default=AFRICA
|
||||
)
|
||||
|
||||
class Meta:
|
||||
verbose_name = "Country"
|
||||
verbose_name_plural = "Countries"
|
||||
|
||||
def __str__(self):
|
||||
return self.name
|
||||
|
||||
class Region(models.Model):
|
||||
id = models.CharField(primary_key=True)
|
||||
name = models.CharField(max_length=100)
|
||||
country = models.ForeignKey(Country, on_delete=models.CASCADE)
|
||||
|
||||
def __str__(self):
|
||||
return self.name
|
||||
|
||||
class VisitedRegion(models.Model):
|
||||
id = models.AutoField(primary_key=True)
|
||||
user_id = models.ForeignKey(
|
||||
User, on_delete=models.CASCADE, default=default_user_id)
|
||||
region = models.ForeignKey(Region, on_delete=models.CASCADE)
|
||||
|
||||
def __str__(self):
|
||||
return f'{self.region.name} ({self.region.country.country_code}) visited by: {self.user_id.username}'
|
Loading…
Add table
Add a link
Reference in a new issue