Django заполнение формы по модалу

У меня проблема с заполнением формы в модальном всплывающем окне. Я могу добавить форму в модальное окно, но я хочу, чтобы она была основана на строке, на которую нажимает пользователь.

Мое представление: class SalesQuotationDetailView(LoginRequiredMixin, View): template_name = 'Sales/quotation_details.html'

def get(self, request, quoteid):
    quotation = Quotation.objects.get(id=quoteid)
    quotationlines = QuotationLine.objects.filter(quotation=quotation, deleted=False)
    company = quotation.customer
    quotationform = QuotationForm(initial=model_to_dict(quotation), companyid=company.id)
    newquotationlineform = NewQuotationLineForm()
    context = {
    'quotation':quotation, 
    'quotationform':quotationform,
    'quotationlines':quotationlines, 
    'new_quotation_line':newquotationlineform,
    'table_title':"Quotation Lines", 
    'table_heading_1':"Article", 
    'table_heading_2':"Amount", 
    'table_heading_3':"Price per Piece", 
    'table_heading_4':"Lead Time", 
    'table_heading_5':"Line total"
    }
    return render(request, self.template_name, context)

def post(self, request, quoteid):
    quotation = Quotation.objects.get(id=quoteid)
    quotationlines = QuotationLine.objects.filter(quotation=quotation, deleted=False)
    company = quotation.customer
    quotationform = QuotationForm(data=request.POST, files=request.FILES, instance=quotation, companyid=company.id)
    if quotationform.has_changed and quotationform.is_valid():
        qform = quotationform.save(commit=False)
        qform.updated_by = request.user
        qform.updated_date = timezone.now()
        quotationform.save()
        messages.success(request, f'{quotation.number} has been saved correctly')
        return redirect('sales-quote-details', quoteid=quotation.id)
    else:
        messages.warning(request, f'{quotationform.errors}')
    newquotationlineform = NewQuotationLineForm(data=request.POST)
    if newquotationlineform.has_changed and newquotationlineform.is_valid():
        newquotationline = newquotationlineform.save(commit=False)
        newquotationline.quotation = quotation
        newquotationline.total_line_price = newquotationline.amount * newquotationline.price
        newquotationline = newquotationlineform.save()
        messages.success(request, f'The new quotation line was added succesfully')
        return redirect('sales-quote-details', quoteid=quotation.id)
    context = {
    'quotation':quotation, 
    'quotationform':quotationform,
    'quotationlines':quotationlines, 
    'new_quotation_line':newquotationlineform,
    'table_title':"Quotation Lines", 
    'table_heading_1':"Article", 
    'table_heading_2':"Amount", 
    'table_heading_3':"Price per Piece", 
    'table_heading_4':"Lead Time", 
    'table_heading_5':"Line total"
    }
    return redirect('sales-quotations')

А мой шаблон:

Я не знаю, как я могу отправить данные из quotationline в форму edit_quotation_line. Сейчас это пустая форма, когда я объявляю ее в представлении. Я хотел бы передавать ее в форму для каждой строки.

Я попробовал использовать include, но это дало мне ту же проблему. Я мог получить доступ к переменным, но не мог заставить форму заполниться данными из строк цитат. Я также попытался сделать extend, но и это не решило проблему, поскольку я не отправлял данные на другую страницу.

Я потратил несколько часов, пытаясь решить эту проблему, но не знаю как, может ли кто-нибудь помочь мне?

Вернуться на верх