how to aasign id on forms.py and how to generates choices on the form of another models for individual id ,choices may be differenet for individual id

9 views
Skip to first unread message

Suzan Bajracharya

unread,
Jan 29, 2019, 7:48:07 AM1/29/19
to Django users
class Medical_Meds(models.Model): medicines=models.CharField(max_length=250) amount=models.IntegerField(default=0) # is_purchase=models.BooleanField(default=False) p_date=models.DateTimeField(default=datetime.now) patient=models.ForeignKey(Patient) medical=models.ForeignKey(Medical) class Medical_Meds_Forms(forms.ModelForm): patient=4, opt = [] # my = Doctor_Patient_Med.objects.all() my = Doctor_Patient_Med.objects.filter(patient=patient) for x in my: opt.append([x.medicines,x.medicines]) total=len(opt) print(total) medicines =forms.MultipleChoiceField(widget=forms.CheckboxSelectMultiple, choices=opt) amount=forms.IntegerField(label='Amount',initial="0") p_date=forms.widgets.DateTimeInput(attrs={'type':'date'}) # p_date = forms.DateTimeField(label='Purchase-Date', widget=forms.DateTimeInput(attrs={'type':'date'})) class Meta: model=Medical_Meds exclude=['patient','doctor','medical']

Reply all
Reply to author
Forward
0 new messages