17 changed files with 138 additions and 0 deletions
Binary file not shown.
|
Binary file not shown.
@ -0,0 +1,3 @@ |
|||||||
|
from django.contrib import admin |
||||||
|
|
||||||
|
# Register your models here. |
@ -0,0 +1,5 @@ |
|||||||
|
from django.apps import AppConfig |
||||||
|
|
||||||
|
|
||||||
|
class RecipesConfig(AppConfig): |
||||||
|
name = 'recipes' |
Binary file not shown.
Binary file not shown.
@ -0,0 +1,52 @@ |
|||||||
|
from csv import DictReader |
||||||
|
from datetime import datetime |
||||||
|
|
||||||
|
from django.core.management import BaseCommand |
||||||
|
|
||||||
|
from recipes.models import Recipe |
||||||
|
from pytz import UTC |
||||||
|
|
||||||
|
|
||||||
|
DATETIME_FORMAT = '%m/%d/%y' |
||||||
|
|
||||||
|
# VACCINES_NAMES = [ |
||||||
|
# 'Canine Parvo', |
||||||
|
# 'Canine Distemper', |
||||||
|
# 'Canine Rabies', |
||||||
|
# 'Canine Leptospira', |
||||||
|
# 'Feline Herpes Virus 1', |
||||||
|
# 'Feline Rabies', |
||||||
|
# 'Feline Leukemia' |
||||||
|
# ] |
||||||
|
|
||||||
|
ALREADY_LOADED_ERROR_MESSAGE = """ |
||||||
|
If you need to reload the data from the CSV file, |
||||||
|
first delete the db.sqlite3 file to destroy the database. |
||||||
|
Then, run `python manage.py migrate` for a new empty |
||||||
|
database with tables""" |
||||||
|
|
||||||
|
|
||||||
|
class Command(BaseCommand): |
||||||
|
# Show this when the user types help |
||||||
|
help = "Loads data from the csv into our model" |
||||||
|
|
||||||
|
def handle(self, *args, **options): |
||||||
|
if Recipe.objects.exists(): |
||||||
|
print('Data already loaded...exiting.') |
||||||
|
print(ALREADY_LOADED_ERROR_MESSAGE) |
||||||
|
return |
||||||
|
print("Creating data") |
||||||
|
for row in DictReader(open('./brewtargetData.csv')): |
||||||
|
recipe = Recipe() |
||||||
|
recipe.name = row['title'] |
||||||
|
recipe.style = row['style'] |
||||||
|
recipe.author = row['author'] |
||||||
|
recipe.notes = row['notes'] |
||||||
|
recipe.batchSize = row['batch size'] |
||||||
|
recipe.batchSizeUnit = row['batch size unit'] |
||||||
|
recipe.brewType = row['brew type'] |
||||||
|
raw_creation_date = row['creation date'] |
||||||
|
creation_date = UTC.localize( |
||||||
|
datetime.strptime(raw_creation_date, DATETIME_FORMAT)) |
||||||
|
recipe.creationDate = creation_date |
||||||
|
recipe.save() |
@ -0,0 +1,28 @@ |
|||||||
|
# Generated by Django 3.0.2 on 2020-01-22 22:05 |
||||||
|
|
||||||
|
from django.db import migrations, models |
||||||
|
|
||||||
|
|
||||||
|
class Migration(migrations.Migration): |
||||||
|
|
||||||
|
initial = True |
||||||
|
|
||||||
|
dependencies = [ |
||||||
|
] |
||||||
|
|
||||||
|
operations = [ |
||||||
|
migrations.CreateModel( |
||||||
|
name='Recipe', |
||||||
|
fields=[ |
||||||
|
('id', models.AutoField(auto_created=True, primary_key=True, serialize=False, verbose_name='ID')), |
||||||
|
('name', models.CharField(max_length=100)), |
||||||
|
('style', models.CharField(blank=True, max_length=100, null=True)), |
||||||
|
('author', models.CharField(blank=True, max_length=100, null=True)), |
||||||
|
('notes', models.TextField(blank=True, null=True)), |
||||||
|
('batchSize', models.DecimalField(decimal_places=3, max_digits=8)), |
||||||
|
('batchSizeUnit', models.CharField(choices=[('Gal', 'Gallons'), ('L', 'Liters')], max_length=3)), |
||||||
|
('brewType', models.CharField(choices=[('Ex', 'Extract'), ('BB', 'Brew in a Bag'), ('AG', 'All Grain')], max_length=2)), |
||||||
|
('creationDate', models.DateTimeField()), |
||||||
|
], |
||||||
|
), |
||||||
|
] |
@ -0,0 +1,13 @@ |
|||||||
|
from django.db import models |
||||||
|
|
||||||
|
class Recipe(models.Model): |
||||||
|
BREW_TYPES = [('Ex', 'Extract'),('BB','Brew in a Bag'),('AG','All Grain')] |
||||||
|
VOL_UNITS = [('Gal', 'Gallons'),('L', 'Liters')] |
||||||
|
name = models.CharField(max_length=100) |
||||||
|
style = models.CharField(max_length=100, null=True, blank=True) |
||||||
|
author = models.CharField(max_length=100, null=True, blank=True) |
||||||
|
notes = models.TextField(null=True, blank=True) |
||||||
|
batchSize = models.DecimalField(decimal_places=3, max_digits=8) |
||||||
|
batchSizeUnit = models.CharField(choices=VOL_UNITS, max_length=3) |
||||||
|
brewType = models.CharField(choices=BREW_TYPES, max_length=2) |
||||||
|
creationDate = models.DateTimeField() |
@ -0,0 +1,3 @@ |
|||||||
|
from django.test import TestCase |
||||||
|
|
||||||
|
# Create your tests here. |
Loading…
Reference in new issue