I am using djnago-extra-views, but the template says (Hidden field TOTAL_FORMS) This field is required.

Asked 3 months ago, Updated 3 months ago, 8 views

Note

We have posted a similar question on the following site.
teratail
Qiita

Problems you are having

I would like to create an inline form using django-extra-views, but when I try to display the form, the inline form is shown as follows:

Image Description

environment

django 3.2
django-extra-views 0.7.1 (current state of affairs)

Tried

I read the djnago-extra-views documentation and write the code exactly as it says.

Also, when I looked into it, I thought it was related to a form set, but I didn't have much information to solve it.

Source Codes Affected

models.py

class Property (models.Model):
    customer_id=models.ForeignKey (Customer, on_delete=models.CASCADE, null=True)
    name=models.CharField(max_length=32, blank=True)
    address=models.CharField('Address', max_length=32, blank=True)
    created_at=models.DateTimeField(auto_now_add=True)
    updated_at=models.DateTimeField(auto_now=True)

    def__str__(self):
        return self.name
    
    default_absolute_url(self):
        return reverse("properties:properties")

class Estimate (models.Model):
    estimate_id=models.CharField (blank=True, max_length=255)
    property_id=models.ForeignKey(Property, on_delete=models.CASCADE, related_name="property")
    ref_customer_id=models.ForeignKey (Customer, on_delete=models.CASCADE, null=True)
    customer_name=models.CharField('CustomerName', max_length=255)
    customer_email=models.EmailField('Customer Email Address', max_length=255, blank=True)
    customer_tel=models.CharField ('Customer Phone Number', max_length=11, blank=True)
    customer_postal_code=models.CharField('Customer Zip Code', max_length=1024, blank=True)
    customer_address=models.CharField('Customer Address', blank=True, max_length=1024)
    ref_property_id=models.IntegerField('Property ID', blank=True, default=0)
    property_address=models.CharField('Property Address', max_length=1024, blank=True)
    version=models.CharField("Version", max_length=255, blank=True)
    estimated_amount=models.IntegerField('Quote', default=0')
    estimated_pdf=models.CharField('Quote', max_length=255, blank=True)
    created_at=models.DateTimeField(auto_now_add=True)
    updated_at=models.DateTimeField(auto_now=True)    
    
    def__str__(self):
        return self.customer_name

views.py

from extra_views import CreateWithInlinesView, InlineFormSetFactory


classEstimateInline(InlineFormSetFactory):
    model=Estimate
    fields=["estimate_id" ]


classCreatePropertyView (CreateWithInlinesView):
    model=Property
    inlines= [EstimateInline]
    fields=["customer_id", "name", "address" ]
    template_name = 'tect/properties/estimates/create.html'
    
    def get_success_url(self):
        return self.object.get_absolute_url()

create.html

<form action="method="post">{%csrf_token%}
            {{ form.as_p}}

            {% for formset in inlines%}
                {{ formset}}
            {% endfor%}

            <div class="d-grid col-3mx-autopt-5">
                <button class="btn btn-outline-dark shadow" type="submit"">Save</button>
            </div>
        </div>
</form>

python python3 django

2022-09-30 11:50

1 Answers

It's solved.It seems that the fix was not reflected due to the problem with the browser cache.After a while, I tried to display it again and it was displayed successfully.


2022-09-30 11:50

If you have any answers or tips


© 2023 OneMinuteCode. All rights reserved.