@ -1,7 +1,15 @@
|
||||
from django import forms
|
||||
from django.urls import reverse
|
||||
from django.utils import timezone
|
||||
from django.http import HttpResponse, HttpResponseRedirect
|
||||
from .models import Yeast, Propogation, Strain
|
||||
from .models import Yeast, Propogation, Strain, Storage
|
||||
from beer.models import Batch
|
||||
|
||||
|
||||
class MyModelChoiceField(forms.ModelChoiceField):
|
||||
def label_from_instance(self, obj):
|
||||
return obj.name
|
||||
|
||||
|
||||
import logging
|
||||
logger = logging.getLogger('django')
|
||||
@ -31,7 +39,7 @@ class BatchAddForm(forms.ModelForm):
|
||||
class Meta:
|
||||
# specify model to be used
|
||||
model = Propogation
|
||||
|
||||
|
||||
# specify fields to be used
|
||||
fields = [
|
||||
'production_date',
|
||||
@ -46,15 +54,70 @@ class BatchAddForm(forms.ModelForm):
|
||||
num_samples = forms.IntegerField()
|
||||
|
||||
class StrainAddForm(forms.ModelForm):
|
||||
|
||||
|
||||
# create meta class
|
||||
class Meta:
|
||||
# specify model to be used
|
||||
model = Strain
|
||||
|
||||
|
||||
# specify fields to be used
|
||||
fields = [
|
||||
'name',
|
||||
'long_name',
|
||||
'manufacturer',
|
||||
]
|
||||
|
||||
class PitchIntoBeerForm(forms.Form):
|
||||
batch = forms.ModelChoiceField(queryset=Batch.objects.all())
|
||||
starter = forms.BooleanField(required=False)
|
||||
sample = forms.ModelChoiceField(queryset=Yeast.available)
|
||||
|
||||
def pitch_sample(self):
|
||||
sample = self.cleaned_data['sample']
|
||||
sample.pitched = True
|
||||
sample.pitched_batch = self.cleaned_data['batch']
|
||||
sample.date_pitched = timezone.now()
|
||||
sample.save()
|
||||
|
||||
class PropogateSampleForm(forms.Form):
|
||||
num = forms.IntegerField(min_value=1)
|
||||
storage = forms.ModelChoiceField(queryset=Storage.objects.all())
|
||||
parent = forms.ModelChoiceField(queryset=Yeast.available)
|
||||
strain = forms.ModelChoiceField(queryset=Strain.objects.all())
|
||||
|
||||
def create_propogation(self):
|
||||
samples = self.cleaned_data['num']
|
||||
storage = self.cleaned_data['storage']
|
||||
parent = self.cleaned_data['parent']
|
||||
strain = self.cleaned_data['strain']
|
||||
|
||||
# send email using the self.cleaned_data dictionary
|
||||
prop_obj = Propogation(
|
||||
production_date=timezone.now(),
|
||||
strain = strain,
|
||||
source = 'PR',
|
||||
notes = 'Auto generated from form.'
|
||||
)
|
||||
|
||||
prop_obj.save()
|
||||
prop_obj.parent.add(parent)
|
||||
|
||||
for i in range(samples):
|
||||
if storage.name == 'Deep Freeze':
|
||||
cells = 40
|
||||
else:
|
||||
cells = 100
|
||||
|
||||
yeast = Yeast(
|
||||
propogation = prop_obj,
|
||||
generation_num = parent.generation_num + 1,
|
||||
storage = storage,
|
||||
pitched = False,
|
||||
cellcount = cells,
|
||||
notes = 'Auto generated from form.'
|
||||
)
|
||||
|
||||
yeast.save()
|
||||
|
||||
return prop_obj
|
||||
|
||||
|
Reference in New Issue
Block a user