django handle multiple forms -
my model:
class hospitaldoctor(models.model): hospital = models.foreignkey(hospital) full_name = models.charfield(max_length=100, unique=true) expertization = models.charfield(max_length=50) nmc_no = models.charfield(max_length=20) timings = models.manytomanyfield('timing', related_name='shift_timing') appointment = models.integerfield(default=0) def __unicode__(self): homecoming self.full_name class timing(models.model): hospital = models.foreignkey(hospital) doc = models.foreignkey(hospitaldoctor) day = models.charfield(max_length=20) mng_start = models.integerfield() mng_end = models.integerfield() eve_start = models.integerfield() eve_end = models.integerfield() def __unicode__(self): homecoming self.day
and have created form this:
class hospitaldoctorinfoform(forms.modelform): class meta: model = hospitaldoctor fields = ('hospital','full_name', 'expertization', 'nmc_no') class timingform(forms.modelform) class meta: model = timing fields = ('day','mng_start', 'mng_end', 'eve_start', 'eve_end')
i want save 2 form @ once. timingform contains schedule of doc 1 week need 7 forms 7 days , day should set per week sunday, monday....doctorinfoform contains info doctor.
i tried using createview need utilize form_class there?
how can create possible? suggestion.
it simple in django.
if hospitaldoctorinfoform.is_valid() , timingform.is_valid(): #dosomething hospitaldocinfoform.save() timingform.save()
bingo!!
django multiple-forms formsets
No comments:
Post a Comment