Some models and stuff

This commit is contained in:
Kumi 2022-08-04 17:58:57 +02:00
parent a38d324bdb
commit eeb846d17b
Signed by: kumi
GPG key ID: 6C2B851B15DF1681
14 changed files with 128 additions and 7 deletions

2
core/helpers/__init__.py Normal file
View file

@ -0,0 +1,2 @@
from .geo import get_coords_for_address
from .media import uuid_path

9
core/helpers/geo.py Normal file
View file

@ -0,0 +1,9 @@
from geopy.geocoders import Nominatim
from restoroo.const import USER_AGENT
def get_coords_for_address(*address):
nominatim = Nominatim(user_agent=USER_AGENT)
nominatim.geocode(", ".join(*address))
return location.latitude, location.longitude

5
core/helpers/media.py Normal file
View file

@ -0,0 +1,5 @@
import uuid
def uuid_path(instance, filename):
return f'{uuid.uuid4()}/{filename}'

View file

@ -1 +1,2 @@
from .auth import User
from .profiles import Profile

22
core/models/billing.py Normal file
View file

@ -0,0 +1,22 @@
from django.db import models
from django.utils.translation import gettext as _
class ExpenseTypeChoices(models.IntegerChoices):
MONTHLY_FEE = (0, _("Monthly Fee"))
SUPPORT = (1, _("Support"))
DEVELOPMENT = (2, _("Custom Development"))
COMMISSION = (3, _("Commission"))
CONTRIBUTION = (4, _("Contribution"))
class RelatedModelChoices(models.IntegerChoices):
CHAIN = (0, _("Chain"))
RESTAURANT = (1, _("Restaurant"))
ROOM = (2, _("Room"))
TABLE = (3, _("Table"))
class Expense(models.Model):
expense_type = models.IntegerField(choices=ExpenseTypeChoices.choices(), null=True, blank=True)
text = models.CharField(max_length=256)

25
core/models/businesses.py Normal file
View file

@ -0,0 +1,25 @@
from django.db import models
from .media import Image
from .geo import Location
class Chain(models.Model):
'''
Model for "Restaurant Chains"
Each Restaurant belongs to a Chain just in case any large corporation
running several different chains comes around...
'''
name = models.CharField(max_length=128)
logo = models.ForeignKey(Image, models.PROTECT, null=True)
class Restaurant(models.Model):
'''
Model representing an individual Restaurant within a Chain
'''
name = models.CharField(max_length=128)
logo = models.ForeignKey(Image, models.PROTECT, null=True)
location = models.ForeignKey(Location, models.PROTECT)
maximum_capacity = models.PositiveSmallIntegerField(null=True, blank=True)

15
core/models/geo.py Normal file
View file

@ -0,0 +1,15 @@
from django.contrib.gis.db import models
from django_countries.fields import CountryField
class Location(models.Model):
address = CharField(max_length=256)
address2 = CharField(max_length=256, null=True, blank=True)
city = CharField(max_length=128)
zipcode = CharField(max_length=16)
state = CharField(max_length=128)
country = CountryField()
floor = CharField(max_length=16, null=True, blank=True)
door = CharField(max_length=16, null=True, blank=True)

15
core/models/layout.py Normal file
View file

@ -0,0 +1,15 @@
from django.db import models
from .businesses import Restaurant
class Room(models.Model):
restaurant = models.ForeignKey(Restaurant, models.CASCADE)
name = models.CharField(max_length=128)
maximum_capacity = models.PositiveSmallIntegerField(null=True, blank=True)
class Table(models.Model):
room = models.ForeignKey(Room, models.CASCADE)
number = models.CharField(max_length=64)
capacity = models.PositiveSmallIntegerField(null=True, blank=True)

8
core/models/media.py Normal file
View file

@ -0,0 +1,8 @@
from django.db import models
from ..helpers.media import uuid_path
class Image(models.Model):
name = models.CharField(max_length=256)
file = models.ImageField(upload_to=uuid_path)

12
core/models/profiles.py Normal file
View file

@ -0,0 +1,12 @@
from django.db import models
from django.contrib.auth import get_user_model
class Profile(models.Model):
'''
Model for additional user data, so we don't have to touch the actual auth model for that
'''
user = models.OneToOneField(get_user_model(), on_delete=models.PROTECT, primary_key=True)
first_name = models.CharField(max_length=128)
last_name = models.CharField(max_length=128)
display_name = models.CharField(max_length=128)

View file

View file

@ -2,3 +2,6 @@ Django
django-autosecretkey
dbsettings
argon2-cffi
geopy
django-countries[pyuca]
pillow

1
restoroo/const.py Normal file
View file

@ -0,0 +1 @@
USER_AGENT = "Restoroo by Kumi Systems (https://kumi.systems/)"

View file

@ -67,12 +67,15 @@ WSGI_APPLICATION = 'restoroo.wsgi.application'
# Database
# https://docs.djangoproject.com/en/4.0/ref/settings/#databases
DATABASES = {
if CONFIG_FILE.config.has_section("MariaDB"):
pass # TODO
else:
DATABASES = {
'default': {
'ENGINE': 'django.db.backends.sqlite3',
'NAME': BASE_DIR / 'db.sqlite3',
}
}
}
# Password validation