brewery-website/beer/models.py
2024-05-30 16:26:55 -04:00

33 lines
1007 B
Python

from django.db import models
from django.utils import timezone
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 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.ForeignKey('BatchRecipe', on_delete=models.CASCADE, default=1)
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)
class Recipe(CustomModel):
""" Recipes not attched to batches."""
name = models.CharField(max_length=50)