Say I have a model
class MyModel(model.Models):
name = model.CharField()
age = model.IntField()
Then in my template I want to display the name
but only allow age
to be changed i.e the user should not be able to modify what is written in the name
field but it should just be there to show, which name they are editing the age for.
My template is as the following
{% extends "myapp/base.html" %}
{% load static %}
{% block content %}
{% load crispy_forms_tags %}
<div class="content-section">
<div class="form-group">
{{form.name|as_crispy_field}} <!-- Can still edit this field -->
<form method="POST">
{% csrf_token %}
{{form.age|as_crispy_field}}
<button class="btn btn-outline-success" type="submit">Update</button>
<a role="button" class="btn btn-outline-info" href="{% url 'my_list' %}"> Wups, take me back!</a>
</div>
</form>
</div>
{% endblock content %}