from django import forms from django.urls import reverse from django.http import HttpResponse, HttpResponseRedirect from .models import Yeast, Propogation, Strain import logging logger = logging.getLogger('django') class DateInput(forms.DateInput): input_type = 'date' class YeastModelForm(forms.ModelForm): class Meta: model = Yeast fields = '__all__' def __init__(self, *args, **kwargs): forms.ModelForm.__init__(self, *args, **kwargs) self.fields['parent'].queryset = Yeast.objects.all() # creating a form class BatchAddForm(forms.ModelForm): def __init__(self, *args, **kwargs): super(BatchAddForm, self).__init__(*args, **kwargs) self.fields['strain'].help_text = 'Add a new strain'.format(reverse('yeast:addstrain')) # create meta class class Meta: # specify model to be used model = Propogation # specify fields to be used fields = [ 'production_date', 'strain', 'source', ] widgets = { 'production_date': DateInput(), } 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', ]