Making A Field Read Only

26 views
Skip to first unread message

Ray Z

unread,
Nov 6, 2019, 11:35:48 AM11/6/19
to Django users
Hey Everyone,

 Im very new to django and im trying to figure out how to make a field on a forum read only. The field is my date created field that has a automatic timestamp. The form structure im using is a modelform  . Here is my code of my forms.py . I appreciate the help. Thank you everyone !


from django import forms
from django.forms import ModelForm
from .models import StudentCheck
from django.utils.translation import gettext_lazy as _



class NewStudentForm(forms.ModelForm):
     class Meta:
        model = StudentCheck
        fields = '__all__'  
        labels = {'date_created':_('Date Created'), 'startdate':_('Start Date'), 'esy':_('ESY')}


models.py

from django.db import models
from django.utils import timezone
from django.forms import ModelForm


# Create your models here.

class StudentCheck (models.Model):
    startdate = models.DateField(max_length= 10 )  
    esy = models.BooleanField(default = False)
    ten_month_school_year = models.BooleanField(default= False)
    other = models.BooleanField(default = False)
    intakedate = models.DateField(max_length=10)
    grade = models.CharField(max_length=2)
    date_created = models.DateTimeField(default=timezone.now)
    firstname = models.CharField(max_length=50)
    lastname = models.CharField(max_length=60)
    address = models.CharField(max_length=100)
    city = models.CharField(max_length=100)
    state = models.CharField(max_length=30)
    zipcode = models.CharField(max_length=5)
    parent_one_name = models.CharField(max_length= 100)
    parent_one_phone = models.CharField(max_length=100)
    parent_one_email = models.CharField(max_length=100)
    parent_two_name = models.CharField(max_length=100)
    parent_two_phone = models.CharField(max_length=12)
    parent_two_email = models.CharField(max_length=100)

        
    def __str__(self):
        return self.lastname

class StudentCheckForm (ModelForm):
    class Meta:
         model = StudentCheck
         fields = '__all__'

Derek

unread,
Nov 7, 2019, 1:45:22 PM11/7/19
to Django users
Reply all
Reply to author
Forward
0 new messages