Uncategorized
		
	
	
Model Fieldname restrictions in Django Framework

A Django model is the built-in feature that Django uses to create tables, their fields, and various constraints. In short, Django Models is the SQL of Database one uses with Django. SQL (Structured Query Language) is complex and involves a lot of different queries for creating, deleting, updating or any other stuff related to database. Django models simplify the tasks and organize tables into models.
This article revolves around restrictions on models field names.
Django places some restrictions on Model Field Names.
First create the django project to see this restrictions
django-admin startapp myproj
cd myproj
Then create new app.
python manage.py startapp main
Add main app in settings.py inside the INSTALLED_APPS
Restrictions on Field Name –
1. Field name cannot be a python reserved word
Example 1
Python3
| fromdjango.db importmodels  # Create your models here. classStudent(models.Model):     pass=models.CharField(max_length=100)  | 
Error:
Example 2
Python3
| fromdjango.db importmodels  # Create your models here. classStudent(models.Model):     global=models.CharField(max_length=100) | 
2. A field name cannot contain more than one underscore in a row
Python3
| fromdjango.db importmodels  # Create your models here. classStudent(models.Model):     stu__name =models.CharField(max_length=100)  | 
Error:
3. A field name cannot end with an underscore
Python3
| fromdjango.db importmodels  # Create your models here. classStudent(models.Model):     stuname_ =models.CharField(max_length=100)  | 
Error:
<!–
–>

                Integrating Django with Reactjs using Django REST Framework
            

                Browsable API in Django REST Framework
            

                Customizing Filters in Django REST Framework
            

                Python | Sessions framework using django
            

                Implement Token Authentication using Django REST Framework
            

                Django REST Framework Installation
            

                How to Create a basic API using Django Rest Framework ?
            

                Boolean Fields in Serializers – Django REST Framework
            

                String Fields in Serializers – Django REST Framework
            

                Core arguments in serializer fields – Django REST Framework
            
 
				 
					



Please Login to comment…