S
S
San4ouZ2018-06-07 22:51:33
Django
San4ouZ, 2018-06-07 22:51:33

Is it possible to combine a form field in a formset?

Good day. It is necessary to make a schedule of classes for an educational institution. Tell me how best to make a form for adding a schedule, so that it looks like this:
5b1989bcd22e1219072155.png
So far, I could only do this, through inlineformset_factory:
5b198a0d52fab840729698.png
So, is it possible to somehow combine the "Date" fields of the forms in the formset, or, let's say, do field "Date" in the first form is visible, and in the other three - invisible, and assign them the value of the field of the first form?
Or in general it is possible to do without formset?
views.py:

import mimetypes
import os
from django.shortcuts import render
from .forms import ScheduleForm
from django.http import HttpResponseRedirect, HttpResponse
from django.forms import inlineformset_factory
from .models import Schedule
from groups.models import Group


def addschedule(request, gn=''):
    gnum = Group.objects.get(pk=gn)
    model_formset = inlineformset_factory(parent_model=Group, model=Schedule, form=ScheduleForm, exclude=[], extra=24,
                                          can_delete=False)
    if request.POST:
        formset = model_formset(request.POST, request.FILES, instance=gnum)
        if formset.is_valid():
            estates_objects = formset.save(commit=False)
            for form in formset:
                form.save()
            return render(request, 'main/mainpage.html', locals())
    else:
        formset = model_formset(queryset=Schedule.objects.all())
        return render(request, 'schedule/schedule.html', locals())

Answer the question

In order to leave comments, you need to log in

1 answer(s)
K
Konstantin Malyarov, 2018-06-08
@Konstantin18ko

Show the views.py file.

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question