46 lines
1.5 KiB
Python
46 lines
1.5 KiB
Python
from django.db import models
|
|
from django.utils import timezone
|
|
from django_cryptography.fields import encrypt
|
|
|
|
from config.extras import BREWFATHER_APP_ROOT
|
|
from django.conf import settings
|
|
|
|
import logging
|
|
logger = logging.getLogger('django')
|
|
|
|
class CustomModel(models.Model):
|
|
""" Custom model class with default fields to use. """
|
|
created_date = models.DateTimeField(default=timezone.now)
|
|
|
|
class Meta:
|
|
abstract = True
|
|
|
|
class UserProfile(CustomModel):
|
|
user = models.OneToOneField(settings.AUTH_USER_MODEL, on_delete=models.CASCADE)
|
|
brewfather_api_user = encrypt(models.TextField(max_length=128))
|
|
brewfather_api_key = encrypt(models.TextField(max_length=128))
|
|
|
|
def __str__(self):
|
|
return self.user.username
|
|
|
|
class Batch(CustomModel):
|
|
brewfather_id = models.CharField(max_length=50)
|
|
brewfather_num = models.IntegerField(default=1)
|
|
brewfather_name = models.CharField(max_length=500, default='name')
|
|
recipe = models.OneToOneField('BatchRecipe', on_delete=models.CASCADE, default=1)
|
|
|
|
@property
|
|
def brewfather_url(self):
|
|
return '{}/tabs/batches/batch/{}'.format(BREWFATHER_APP_ROOT, self.brewfather_id)
|
|
|
|
def __str__(self):
|
|
# Return a string that represents the instance
|
|
return 'BF #{num}: {name}'.format(name=self.brewfather_name, num=self.brewfather_num)
|
|
|
|
class BatchRecipe(CustomModel):
|
|
""" Recipe to be stored with a batch."""
|
|
name = models.CharField(max_length=50)
|
|
batch_recipe = models.BooleanField(null=True)
|
|
recipe_json = models.TextField(null=True, blank=True)
|
|
|