Django how to enter multiple records on one form -


i writing calendar app following models:

class calendarhour(models.model):     '''     each day there many events, e.g. @ 10 am, framer orders     material, etc.     '''     day_id = models.foreignkey(calendarday)     time = models.timefield()     work = models.textfield()      def __unicode__(self):         return 'work took place @ {work_time}'.format(work_time = self.time)  class calendarday(models.model):     '''     each project has many daily logs.  but, each daily log belongs     1 project (onetomany relationship)     '''     company_id = models.foreignkey(companycalendar)     day_date = models.datefield(auto_now_add = true) # recording date each log entered in     deadline = models.datefield() # date daily log 

now, want create form based on these models has information day, 24 rows of entry instances, each representing 1 hour. so, in forms.py: #forms.py django.forms import modelform

class hourform(modelform):     class meta:          model = calendarhour         fields = ['entry_id', 'day_date', 'deadline']  class dayform(modelform):     class meta:         model = calendarday         fields = ['company_id', 'day_date', 'deadline']  # in views.py: ... class calendarsubmit(view):     template_name = 'calendar/submit.html'     today_calendar = calendarday     each_hour_calendar = calendarhour      def get(self, request):         return render(request, self.template_name, {'form1': self.toady_calendar, 'form2':self.each_hour_calendar })      def post(self, request):         today = self.today_calendar(request.post)         each_hour = self.each_hour_calendar(request.post)          if today.is_valid():                       today_calendar.save()          if each_hour.is_valid():             each_hour_calendar.save() 

now, can show 2 different forms in template, form_day , form_hour. can repeat form2 fields 24 times, when posted, first hour ends in database , others ignored. know in admin, there add buttom adds multiple instances, not know how achieve in case: how display 2 relating models on 1 form referring model needs populated multiple times.

any appreciated.


Comments