The django documentation suggests that I can identify hidden / visible fields from my template. I have two models: AddressInfo and PharmacyInfo. I need to enter data for both tables from one page. I want to hide the address_id field (from the PharmacyInfo model). I currently have:
{% for form in formset %} {% if form.non_field_errors %} <div class="form_errors"> {{ form.non_field_errors }} </div> {% endif %} {% for field in form.visible_fields%} <div class="field_content"> <label>{{field.label_tag }}</label> <div class="field"> {% if field.help_text %} <div class = "help_text"> {{ field.help_text }} </div> {% endif %} {{ field }} {{ field.errors }} </div> </div> {% endfor %} {% endfor %} class PharmForm(ModelForm): class Meta: model = PharmInfo widgets = { 'address_id': forms.HiddenInput() } class AddressForm(ModelForm): class Meta: model = AddressInfo class AddressInfo(models.Model): address_id = models.AutoField(primary_key=True) address_1 = models.CharField("Address Line 1", max_length = 64) address_2 = models.CharField("Address Line 2", max_length = 64, blank=True, null=True) address_3 = models.CharField("Address Line 3", max_length = 64, blank=True, null=True) address_4 = models.CharField("Address Line 4", max_length = 64, blank=True, null=True) town_city = models.CharField("Town or City", max_length = 32) post_code = models.CharField("Post Code", max_length = 8) phone = models.CharField("Phone Number - numbers 0-9 only", max_length = 16)
This code hides the input field for the address_id field, but the label is still displayed. I want to hide the entire div, but 'form.visible_fields' does not exclude it from the output. It drives me crazy. Can someone tell me how to mark the address_id field in a way visible to the template.
source share