Django forms access (file) field from relation

I have a view that locks like this:

  def table_form_combined(request: HttpRequest) -> HttpResponse:
    if request.method == "POST":

        formset = TransActionFormSet(data=request.POST)
        if formset.is_valid():

    return render(request, "evidence/table_form_combined.html", {'formset': TransActionFormSet})

My Form looks like this:

class TransactionForm(ModelForm):
    class Meta:
        model = Transaction
        fields = ("source_id", "transaction_date", "data", "evidence", "meta_data")
        widgets = {
            'data': Textarea(attrs={'rows': 1}),  # set the row amount of
            # the data Text fields to 1 --> data : Name of Textfield in Model

My model (just the relevant stuff):

class TransactionEvidence(Base):
    file = models.FileField(upload_to='evidence/')
class Transaction(Base):

    evidence = models.ForeignKey(
        help_text="A evidence file (i.e. pdf invoice) that can be assigned to a transaction.",

    source_id = models.CharField(
        "Source ID", max_length=150

    transaction_date = models.DateTimeField(, help_text="The transaction date")

And finally, my template locks like this:

{% extends "website/base.html" %}
{% block content %}

    <table class="table">
                <th scope="col"> # </th>
                <th scope="col"> Name </th>
                <th scope="col"> Transaction Date </th>
                <th scope="col"> Data</th>
                <th scope="col"> Evidence</th>
                <th scope="col"> file</th>
                <th scope="col"> Amount</th>
        {{ formset.management_form }}
        {% comment %}
            without that, the form will be invalid
        {% endcomment %}
        {% for form in formset  %}
        <form method="post" enctype="multipart/form-data">

            {% csrf_token %}
            {% if form.source_id.value %}

                    {{form.transaction_date.value }}
                    {{form.transaction_date.as_hidden }}
                    <button name="submit" type="submit" class="btn btn-primary">Submit</button>
            {% endif %}

        {% endfor %}

    <div class="offset-10 col-2">
{% endblock %}

I'm new to django and want to archive a customizable table where I can Update Data. But only the files. Right now it locks like this: enter image description here

And this is pretty close to what I want, but can somebody help me and explain on how to add the file field of the TransactionEvidence Model?


Back to Top