https://docs.djangoproject.com/en/2.2/ref/models/fields/#editable
On Wednesday, 6 November 2019 18:35:48 UTC+2, Ray Z wrote:
-- On Wednesday, 6 November 2019 18:35:48 UTC+2, Ray Z wrote:
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 formsfrom django.forms import ModelFormfrom .models import StudentCheckfrom django.utils.translation import gettext_lazy as _class NewStudentForm(forms.ModelForm): class Meta:model = StudentCheckfields = '__all__'labels = {'date_created':_('Date Created'), 'startdate':_('Start Date'), 'esy':_('ESY')}
models.pyfrom django.db import modelsfrom django.utils importtimezone from django.forms importModelForm # 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.lastnameclass StudentCheckForm (ModelForm ):class Meta:model = StudentCheckfields = '__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+unsubscribe@googlegroups.com.
To view this discussion on the web visit https://groups.google.com/d/msgid/django-users/31713c5f-3d9e-49b1-848d-9ffcb8d2e0a9%40googlegroups.com.
No comments:
Post a Comment