87 lines
2.6 KiB
Python
87 lines
2.6 KiB
Python
from django import forms
|
|
from module_project import constants
|
|
from .models import Intolerance, Symptoms, PastTreatment, ChronicCondition
|
|
from module_iam.models import IAmPrincipal
|
|
|
|
class IntoleranceForm(forms.ModelForm):
|
|
class Meta:
|
|
model = Intolerance
|
|
fields = ['name', 'duration']
|
|
label = {
|
|
"name": "intolerance",
|
|
"duration": "For how long have you been experiencing this intolerance"
|
|
}
|
|
|
|
def save(self, principal_id, commit=True):
|
|
instance = super().save(commit=False)
|
|
instance.principal = IAmPrincipal.objects.get(pk=principal_id)
|
|
if commit:
|
|
instance.save()
|
|
return instance
|
|
|
|
|
|
class SymptomsForm(forms.ModelForm):
|
|
class Meta:
|
|
model = Symptoms
|
|
fields = ['name', 'duration']
|
|
label = {
|
|
"name": "Symptoms",
|
|
"duration": "For how long have you been experiencing this intolerance"
|
|
}
|
|
|
|
def save(self, principal_id, commit=True):
|
|
instance = super().save(commit=False)
|
|
instance.principal = IAmPrincipal.objects.get(pk=principal_id)
|
|
if commit:
|
|
instance.save()
|
|
return instance
|
|
|
|
class SymptomsForm(forms.ModelForm):
|
|
class Meta:
|
|
model = Symptoms
|
|
fields = ['name', 'duration']
|
|
label = {
|
|
"name": "Symptoms",
|
|
"duration": "For how long have you been experiencing this intolerance"
|
|
}
|
|
|
|
def save(self, principal_id, commit=True):
|
|
instance = super().save(commit=False)
|
|
instance.principal = IAmPrincipal.objects.get(pk=principal_id)
|
|
if commit:
|
|
instance.save()
|
|
return instance
|
|
|
|
|
|
class PastTreatmentForm(forms.ModelForm):
|
|
class Meta:
|
|
model = PastTreatment
|
|
fields = ['name', 'duration']
|
|
label = {
|
|
"name": "PastTreatment",
|
|
"duration": "Treatment Date"
|
|
}
|
|
|
|
def save(self, principal_id, commit=True):
|
|
instance = super().save(commit=False)
|
|
instance.principal = IAmPrincipal.objects.get(pk=principal_id)
|
|
if commit:
|
|
instance.save()
|
|
return instance
|
|
|
|
|
|
class ChronicConditionForm(forms.ModelForm):
|
|
class Meta:
|
|
model = ChronicCondition
|
|
fields = ['name', 'duration']
|
|
label = {
|
|
"name": "Chronic Condition",
|
|
"duration": "For how long have you been experiencing this disease"
|
|
}
|
|
|
|
def save(self, principal_id, commit=True):
|
|
instance = super().save(commit=False)
|
|
instance.principal = IAmPrincipal.objects.get(pk=principal_id)
|
|
if commit:
|
|
instance.save()
|
|
return instance |