Monday, January 28, 2019

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

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']

--
You received this message because you are subscribed to the Google Groups "Django users" group.
To unsubscribe from this group and stop receiving emails from it, send an email to django-users+unsubscribe@googlegroups.com.
To post to this group, send email to django-users@googlegroups.com.
Visit this group at https://groups.google.com/group/django-users.
To view this discussion on the web visit https://groups.google.com/d/msgid/django-users/61b2f836-49db-4d1b-973f-6676a8a734b1%40googlegroups.com.
For more options, visit https://groups.google.com/d/optout.

No comments:

Post a Comment