I created a form widget that automatically adds a new record section at the top of the form, which I donβt want to be there. can someone tell me how to disable this? I just want to display the variables, not the add form.
forms.py
class TemplateVariablesWidget(forms.Widget): template_name = 'sites/config_variables.html' def render(self, name, value, attrs=None): sc_vars = ConfigVariables.objects.filter(type='Showroom') wc_vars = ConfigVariables.objects.filter(type='Major Site') context = { 'SConfigVariables' : sc_vars, 'WConfigVariables' : wc_vars, } return mark_safe(render_to_string(self.template_name, context)) class VariableForm(forms.ModelForm): variables = forms.CharField(widget=TemplateVariablesWidget, required=False) class Meta: model = ConfigVariables fields = "__all__"
admin.py
class ConfigTemplateAdmin(admin.ModelAdmin): list_display = ('device_name', 'date_modified') def change_view(self, request, object_id, form_url='', extra_context=None): extra_context = extra_context or {}
change_view.html
{% block extra_content %} {% if include_template %} {% include include_template %} {% endif %} {% if include_form %} <form method="POST" class="post-form"> {% csrf_token %} {{ include_form.as_p }} </form> {% endif %} {% endblock %}
Downloadable Page
: 
AlexW source share