python - store multiple value in database by taking single value at a time from webpage in django -
1)webpage contains 1 field named:
enter symptom:-|______________| , 2 button named next , none of these
2)whenever user click "next" after entering value fetch data "disease" database , match inserted value
3)show related values stored in database list, user has select list
4)while doing process, inserted value going stored "patienthistory database"
5)whenever user click "none of these", result displayed
result: show disease matching user entered symptoms in database
problem:
i take 1 field in "patienthistory" database can store multiple value(using tag field) according process value goes database 1 one user insert above field
so, how can manage it??
here's code:
models.py
class taggedsymptoms(taggeditembase): content_object = models.foreignkey("disease") class disease(models.model): did = models.autofield(verbose_name='disease id', primary_key=true,default=0) dname = models.charfield(max_length=100) symptoms = taggablemanager(through=taggedsymptoms) #it has values v1,v2,v3,v4 symptoms.rel.related_name = "+" class patienthistory(models.model): phid = models.autofield(verbose_name='history id', primary_key=true,default=0) searchby = models.charfield(max_length=5) dateofsearch = models.datefield(auto_now=true) timeofsearch = models.timefield(auto_now=true)
forms.py
class diseaseform(modelform): dname = forms.charfield(help_text="enter disease") symptoms = tagfield(help_text="enter symptoms separated comma") class meta: model = disease fields = "__all__" class searchform(modelform): name = forms.charfield(label="enter symptom",required=true) context = { 'phistory': patienthistoryform(), 'dis' : diseaseform() } class meta: model = disease fields = "__all__"
views.py
class patfirst(templateview): template_name = 'personal/patfirst.html' def get(self,request): sform = searchform() ddata = disease.objects.all() hdata = patienthistory.objects.all() args = {'sform': sform,'ddata': ddata,'hdata':hdata} return render(request,self.template_name,args) def post(self, request): sform = searchform() if request.post.get('next'): return httpresponse("next clicked"+sform.name ) # take symptom elif request.post.get('noneofthese'): return httpresponse("none clicked") #show result
patfirst.html
<h1>search disease</h1> {{ sform.as_p }} <input type="submit" value="next" name="next"/> <input type="submit" value="none of these" name="noneofthese"/>
Comments
Post a Comment