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__'

-- 
You received this message because you are subscribed to the Google Groups 
"Django users" group.
To unsubscribe from this group and stop receiving emails from it, send an email 
to django-users+unsubscr...@googlegroups.com.
To view this discussion on the web visit 
https://groups.google.com/d/msgid/django-users/b24f33d9-2a88-4bdb-af17-e9913e312b14%40googlegroups.com.

Reply via email to