Make Field Readonly

Ray Zuchowski
Ray Zuchowski used Ask the Experts™
on
I have a field in my database that is displayed on my form in Django that i want to be just readonly. How do i do that ?


Here is my a section of my HTML page.

{% extends 'base.html' %}

{% load crispy_forms_tags %}
{% load static %}
{% block content %}

<br>
<h2>{% load static %}
<img src="{% static 'forms/star.png' %}" alt="chain" height="62" width= "62">  K-8 School Points</h2>
<br>
<br>
<div class = "container">
 <div class= 'row'>
  <div class="col-4"> 
<p> Recording Data as User : {{user.username}} </p>
  </div>
</div>

 <div class= 'row'>
  <div class="col-2"> 
<p>{{form.status|as_crispy_field }}</p>                                <------------This is the field i need to be readonly 
  </div>
</div>
<form method="POST">
    {% csrf_token %}
 <!-- Start Date -->

Open in new window

Comment
Watch Question

Do more with

Expert Office
EXPERT OFFICE® is a registered trademark of EXPERTS EXCHANGE®
IT Director
Commented:
This is done in the forms.py section.

 def __init__(self, *args, **kwargs):
          super (K8PointsForm,self).__init__(*args,**kwargs )
          self.fields['date'].disabled = True
          self.fields['day'].disabled = True
          self.fields['week_of'].disabled = True
          self.fields['status'].disabled = True

Open in new window

Do more with

Expert Office
Submit tech questions to Ask the Experts™ at any time to receive solutions, advice, and new ideas from leading industry professionals.

Start 7-Day Free Trial