0

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):
        return self.full_name

class Timing(models.Model):
    hospital = models.ForeignKey(Hospital)
    doctor = 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):
        return self.day

and I have created form for 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 to save the two form at once. The TimingForm contains the schedule of a doctor for 1 week so I need 7 forms for 7 days and the day should be set as per week initially like Sunday, Monday....DoctorInfoForm contains the information about doctor.

I tried using CreateView but I need to use form_class there?

How can I make it possible? Any suggestion.

4

1 回答 1

0

这在 django 中很简单。

if HospitalDoctorinfoform.is_valid() and Timingform.is_valid():
    #Dosomething
    HospitalDocinfoform.save()
    Timingform.save()

答对了!!

于 2014-10-30T04:29:42.903 回答