{"id":83394,"date":"2021-08-11T09:00:01","date_gmt":"2021-08-11T03:30:01","guid":{"rendered":"https:\/\/techvidvan.com\/tutorials\/?p=83394"},"modified":"2021-08-11T09:00:01","modified_gmt":"2021-08-11T03:30:01","slug":"django-models-and-the-steps-to-create-your-first-model","status":"publish","type":"post","link":"https:\/\/techvidvan.com\/tutorials\/django-models-and-the-steps-to-create-your-first-model\/","title":{"rendered":"Django Models and the Steps to Create Your First Model"},"content":{"rendered":"<p>In our previous article on Django\u2019s MVT architecture, we have done an overview of what Django models are. Till now we know that models are useful for storing and maintaining data in the database.<\/p>\n<p>When a user interacts with a web application through the template, then models are responsible to fulfill the user\u2019s request. The user\u2019s request can either be retrieving some information or making changes to the database. To get a deeper look at models we need to know first what objects are?<\/p>\n<h3>Object in Django<\/h3>\n<p>In easier words, an object is a collection of <strong>properties and actions<\/strong>. Confused? Just continue reading, it\u2019s going to be very interesting.<\/p>\n<p>Well, the main objective of introducing an object is that instead of writing everything as a tedious set of programming instructions, we can club everything and define how they interconnect with each other.<\/p>\n<p>Let me give you an example. Just create an object Dog that will have some <strong>properties<\/strong> such as color, breed, and age. Then it will have some <strong>actions<\/strong> such as bark, eat, run.<\/p>\n<p><strong>Dog<\/strong><\/p>\n<p>color<\/p>\n<p>breed<\/p>\n<p>age<\/p>\n<p>bark()<\/p>\n<p>eat()<\/p>\n<p>run()<\/p>\n<p>So we aim to describe the real things in code with properties (object properties) and actions ( methods).<\/p>\n<h3>Django Models<\/h3>\n<p>Model in Django is an object that is saved in the database. A database is a place in which a user\u2019s information is stored. We can think of a model in the database as a spreadsheet with columns (fields) and rows (data). Generally, each model represents a single database table.<\/p>\n<p>You want to create a web application, right? That means there is a need to interact with the database. The retrieval and interaction with the database are achieved by knowing Structured Query Language (SQL). Does that mean you have to learn SQL? Well, the answer is no. In Django, the complex problem of SQL is easily handled by the models themselves.<\/p>\n<p>Here, Django\u2019s models provide an Object-Relational Mapping (ORM) to the database. ORM is a robust programming technique that makes working with data and relational databases effortless.<\/p>\n<p>ORM simplifies the database programming by providing an easy mapping between the object ( \u2018O\u2019 in ORM) and the database that is put in use. This releases the programmer headache to know about the database structure and the task of learning the complex SQL to manipulate and retrieve data.<\/p>\n<p>After the creation of the model, Dango executes SQL to generate a corresponding table in the database( as shown below in the image). Django also prefixes the table name along with the name of the Django application.<\/p>\n<p><a href=\"https:\/\/techvidvan.com\/tutorials\/wp-content\/uploads\/sites\/2\/2021\/07\/Django-model-normal-image02.jpg\"><img loading=\"lazy\" decoding=\"async\" class=\"aligncenter size-full wp-image-83611\" src=\"https:\/\/techvidvan.com\/tutorials\/wp-content\/uploads\/sites\/2\/2021\/07\/Django-model-normal-image02.jpg\" alt=\"Django model\" width=\"840\" height=\"288\" \/><\/a><\/p>\n<p>&nbsp;<\/p>\n<p><strong>Django model creates a corresponding table in the database<\/strong><\/p>\n<p>\u2018R\u2019 in ORM stands for Relationship. It is used to associate two tables.<\/p>\n<p>The relationship is created by linking both the models with a foreign key. In the above case the \u2018Empid\u2019 field in the Employee table is a key linked to the \u2018Empid\u2019 field in the foreign table Department.<\/p>\n<p><a href=\"https:\/\/techvidvan.com\/tutorials\/wp-content\/uploads\/sites\/2\/2021\/07\/Django-model-normal-image01.jpg\"><img loading=\"lazy\" decoding=\"async\" class=\"aligncenter size-full wp-image-83610\" src=\"https:\/\/techvidvan.com\/tutorials\/wp-content\/uploads\/sites\/2\/2021\/07\/Django-model-normal-image01.jpg\" alt=\"Django model \" width=\"840\" height=\"377\" \/><\/a><\/p>\n<p><strong>Foreign key links in Django models create relationships between tables.<\/strong><\/p>\n<p>This is how the ORM works. It describes the ORM way of using the model data to create a table in the database.<\/p>\n<p><strong>Syntax<\/strong><\/p>\n<p>This is how the syntax of models.py file appears.<\/p>\n<pre class=\"EnlighterJSRAW\" data-enlighter-language=\"generic\">from django.db import models\nclass ModelName(models.Model):\nfield_name = models.Field(**options)\n<\/pre>\n<h3>Create Your First Django Model<\/h3>\n<p>Now we have a good idea about Django models, it\u2019s time to discuss the steps to create your first model.<\/p>\n<p>Well, installing and configuring a database is quite a hefty task, especially for beginners. The Django developers realize this and hence Django installs SQLite automatically. In this tutorial, we will use SQLite to make things unchallenging for you.<\/p>\n<p>For interacting with the database, we need to download a <strong>DB Browser for SQLite<\/strong>. <a href=\"https:\/\/sqlitebrowser.org\/dl\/\">Download the standard installer according to your operating system<\/a>.<\/p>\n<p><a href=\"https:\/\/techvidvan.com\/tutorials\/wp-content\/uploads\/sites\/2\/2021\/07\/DB-Browser.png\"><img loading=\"lazy\" decoding=\"async\" class=\"aligncenter size-full wp-image-83612\" src=\"https:\/\/techvidvan.com\/tutorials\/wp-content\/uploads\/sites\/2\/2021\/07\/DB-Browser.png\" alt=\"Download DB Browser\" width=\"1588\" height=\"828\" \/><\/a><\/p>\n<h4>Step 1: Activating Virtual Environment<\/h4>\n<p>Activating your virtual environment is the foremost step. Start your Windows PowerShell or Command prompt. Proceed to the directory where you have made the setup for the Virtual environment.<\/p>\n<p>Activate your Virtual environment by using the following command:<\/p>\n<pre class=\"EnlighterJSRAW\" data-enlighter-language=\"generic\">(virtual-environment-name)\\Scripts\\activate.bat\n<\/pre>\n<p><a href=\"https:\/\/techvidvan.com\/tutorials\/wp-content\/uploads\/sites\/2\/2021\/07\/Step_1.png\"><img loading=\"lazy\" decoding=\"async\" class=\"aligncenter size-full wp-image-83613\" src=\"https:\/\/techvidvan.com\/tutorials\/wp-content\/uploads\/sites\/2\/2021\/07\/Step_1.png\" alt=\"Django Model Environment Setup\" width=\"1380\" height=\"198\" \/><\/a><\/p>\n<p>This activates the Virtual environment.<\/p>\n<p>Change the directory to your project folder. Here it is named \u201cTechVidvan2\u201d.<\/p>\n<h4>Step 2: Create a new app<\/h4>\n<p>Create a new app by using the following command in your Command Prompt or Windows PowerShell.<\/p>\n<pre class=\"EnlighterJSRAW\" data-enlighter-language=\"generic\">Django-admin startapp Employee<\/pre>\n<h4>Step 3: Install the App<\/h4>\n<p>After creating the app the next important step is to install it on the system.<\/p>\n<p>Go to Visual Studios. Here, you can see the name of the newly created App (Employee) written above the project folder name (TechVidvan2).<\/p>\n<p>Go to the settings.py file under your Project. Add \u2018Employee\u2019 ( Application_name) under the INSTALLED_APPS.<\/p>\n<p>Don\u2019t forget to add a comma after your Application_name.<\/p>\n<p><a href=\"https:\/\/techvidvan.com\/tutorials\/wp-content\/uploads\/sites\/2\/2021\/07\/Step_3.png\"><img loading=\"lazy\" decoding=\"async\" class=\"aligncenter size-full wp-image-83614\" src=\"https:\/\/techvidvan.com\/tutorials\/wp-content\/uploads\/sites\/2\/2021\/07\/Step_3.png\" alt=\"Django Installed Apps\" width=\"728\" height=\"247\" \/><\/a><\/p>\n<p>Save your changes.<\/p>\n<h4>Step 4: Making changes to the model.py file<\/h4>\n<p>Open the models.py file under your Application_name (\u2018Employee\u2019) and write the following code in it.<\/p>\n<p><a href=\"https:\/\/techvidvan.com\/tutorials\/wp-content\/uploads\/sites\/2\/2021\/07\/Step_4.png\"><img loading=\"lazy\" decoding=\"async\" class=\"aligncenter size-full wp-image-83615\" src=\"https:\/\/techvidvan.com\/tutorials\/wp-content\/uploads\/sites\/2\/2021\/07\/Step_4.png\" alt=\"Django Models.Py FIle\" width=\"751\" height=\"250\" \/><\/a><\/p>\n<p>It is always recommended to use database-friendly names for the fields.<\/p>\n<p>Each of our model fields has a related Django <strong>field type<\/strong> and field <strong>options.<\/strong> The \u2018Employee\u2019 model uses two different field types\u2014 IntegerField and CharField. Let\u2019s understand the field options in more detail.<\/p>\n<p><strong>Line 6 and 9:<\/strong> The \u2018Empid\u2019 and \u2018salary\u2019 is a Django IntegerField. An integer field has a value from -2147483648 to 2147483647 which is considered safe in all databases supported by Django.<\/p>\n<p><strong>Line 7 and 8:<\/strong> The \u2018name\u2019 and \u2018address\u2019 field is a Django CharField. A CharField is a short line of text (up to 255 characters). Here, the max_length option sets the maximum length.<\/p>\n<p>There are a lot more field types and field options. We will discuss it in upcoming articles.<\/p>\n<h5>Django Model Fields<\/h5>\n<p>The Model class&#8217;s fields are the names of the mapped table&#8217;s columns. The field names should not contain python reserved words such as clean, save, or delete, etc.<br \/>\nDjango comes with a number of built-in field types.<\/p>\n<table>\n<tbody>\n<tr>\n<td><b>Field Name<\/b><\/td>\n<td><b>Description<\/b><\/td>\n<\/tr>\n<tr>\n<td><b>AutoField<\/b><\/td>\n<td><span style=\"font-weight: 400\">It&#8217;s an IntegerField that increments on its own.<\/span><\/td>\n<\/tr>\n<tr>\n<td><b>BigAutoField<\/b><\/td>\n<td><span style=\"font-weight: 400\">It&#8217;s a 64-bit integer, similar to an AutoField but guaranteed to fit integers between 1 and 9223372036854775807.<\/span><\/td>\n<\/tr>\n<tr>\n<td><b>BigIntegerField<\/b><\/td>\n<td><span style=\"font-weight: 400\">It&#8217;s a 64-bit integer, similar to an IntegerField but guaranteed to fit integers between -9223372036854775808 and 9223372036854775807.<\/span><\/td>\n<\/tr>\n<tr>\n<td><b>BinaryField<\/b><\/td>\n<td><span style=\"font-weight: 400\">A field for storing binary data in its raw form.<\/span><\/td>\n<\/tr>\n<tr>\n<td><b>BooleanField<\/b><\/td>\n<td><span style=\"font-weight: 400\">There is a true\/false field in this field.<\/span><\/p>\n<p><span style=\"font-weight: 400\">A CheckboxInput is the default form widget for this field.<\/span><\/td>\n<\/tr>\n<tr>\n<td><b>CharField<\/b><\/td>\n<td><span style=\"font-weight: 400\">It&#8217;s a date, which is represented by a datetime in Python. Instance of a date<\/span><\/td>\n<\/tr>\n<tr>\n<td><b>DateField<\/b><\/td>\n<td><span style=\"font-weight: 400\">In Python, a date is represented by a datetime. example of a date<\/span><\/td>\n<\/tr>\n<tr>\n<td><b>DecimalField<\/b><\/td>\n<td><span style=\"font-weight: 400\">It&#8217;s a decimal number with a fixed precision that&#8217;s represented in Python by a Decimal object.<\/span><\/td>\n<\/tr>\n<tr>\n<td><b>DurationField<\/b><\/td>\n<td><span style=\"font-weight: 400\">A field for storing time periods.<\/span><\/td>\n<\/tr>\n<tr>\n<td><b>EmailField<\/b><\/td>\n<td><span style=\"font-weight: 400\">It&#8217;s a CharField that verifies the value is an email address.<\/span><\/td>\n<\/tr>\n<tr>\n<td><b>FileField<\/b><\/td>\n<td><span style=\"font-weight: 400\">It&#8217;s a field for uploading files.<\/span><\/td>\n<\/tr>\n<tr>\n<td><b>FloatField<\/b><\/td>\n<td><span style=\"font-weight: 400\">A float instance in Python represents a floating-point number.<\/span><\/td>\n<\/tr>\n<tr>\n<td><b>ImageField<\/b><\/td>\n<td><span style=\"font-weight: 400\">It inherits all of FileField&#8217;s properties and methods, but it also verifies that the uploaded object is a genuine picture.<\/span><\/td>\n<\/tr>\n<tr>\n<td><b>IntegerField<\/b><\/td>\n<td><span style=\"font-weight: 400\">It&#8217;s a number field. In all Django-supported databases, values ranging from -2147483648 to 2147483647 are safe.<\/span><\/td>\n<\/tr>\n<tr>\n<td><b>GenericIPAddressField<\/b><\/td>\n<td><span style=\"font-weight: 400\">In string format, an IPv4 or IPv6 address (e.g. 192.0.2.30 or 2a02:42fe::4).<\/span><\/td>\n<\/tr>\n<tr>\n<td><b>NullBooleanField<\/b><\/td>\n<td><span style=\"font-weight: 400\">Like a BooleanField, but with the addition of NULL as an option.<\/span><\/td>\n<\/tr>\n<tr>\n<td><b>PositiveIntegerField<\/b><\/td>\n<td><span style=\"font-weight: 400\">Similar to an IntegerField, however it must be positive or zero (0).<\/span><\/td>\n<\/tr>\n<tr>\n<td><b>PositiveSmallIntegerField<\/b><\/td>\n<td><span style=\"font-weight: 400\">Similar to a PositiveIntegerField, but only accepts values below a specific (database-dependent) threshold.<\/span><\/td>\n<\/tr>\n<tr>\n<td><b>SlugField<\/b><\/td>\n<td><span style=\"font-weight: 400\">The term &#8220;slug&#8221; comes from the newspaper industry. Slugs are brief labels that contain only letters, numbers, underscores, or hyphens. They&#8217;re commonly found in URLs.<\/span><\/td>\n<\/tr>\n<tr>\n<td><b>TextField<\/b><\/td>\n<td><span style=\"font-weight: 400\">There is a large text field. A Textarea is the default form widget for this field.<\/span><\/td>\n<\/tr>\n<tr>\n<td><b>TimeField<\/b><\/td>\n<td><span style=\"font-weight: 400\">A datetime.time instance in Python represents a time.<\/span><\/td>\n<\/tr>\n<tr>\n<td><b>URLField<\/b><\/td>\n<td><span style=\"font-weight: 400\">URLValidator validates a CharField for a URL.<\/span><\/td>\n<\/tr>\n<tr>\n<td><b>UUIDField<\/b><\/td>\n<td><span style=\"font-weight: 400\">A field for storing IDs that are universally unique. The UUID class in Python is used. This stores in an uuid data type in PostgreSQL, otherwise in a char data type (32).<\/span><\/td>\n<\/tr>\n<\/tbody>\n<\/table>\n<h5>Field Options<\/h5>\n<p>Field Options are the arguments given to each field in order to apply a constraint or impart a specific attribute to that field. If you give CharField the option null = True, it will allow you to store empty values for that table in a relational database.<\/p>\n<p>The field choices and attributes that a CharField can use are listed below.<\/p>\n<table>\n<tbody>\n<tr>\n<td><b>Field Options<\/b><\/td>\n<td><b>Description<\/b><\/td>\n<\/tr>\n<tr>\n<td><b>Null<\/b><\/td>\n<td><span style=\"font-weight: 400\">If True, Django stores empty values in the database as NULL. False is the default value.<\/span><\/td>\n<\/tr>\n<tr>\n<td><b>Blank<\/b><\/td>\n<td><span style=\"font-weight: 400\">If True, the field can be left blank. False is the default value.<\/span><\/td>\n<\/tr>\n<tr>\n<td><b>db_column<\/b><\/td>\n<td><span style=\"font-weight: 400\">The name of the database column that will be used to populate this field. Django will use the field&#8217;s name if this isn&#8217;t specified.<\/span><\/td>\n<\/tr>\n<tr>\n<td><b>Default<\/b><\/td>\n<td><span style=\"font-weight: 400\">This is the field&#8217;s default value. This can be a callable object or a value. If it&#8217;s callable, it&#8217;ll be invoked whenever a new object is created.<\/span><\/td>\n<\/tr>\n<tr>\n<td><b>help_text<\/b><\/td>\n<td><span style=\"font-weight: 400\">Additional &#8220;help&#8221; text to be displayed in conjunction with the form widget. Even if your field isn&#8217;t used on a form, it&#8217;s useful for documentation.<\/span><\/td>\n<\/tr>\n<tr>\n<td><b>primary_key<\/b><\/td>\n<td><span style=\"font-weight: 400\">If True, this field is the model&#8217;s primary key.<\/span><\/td>\n<\/tr>\n<tr>\n<td><b>editable<\/b><\/td>\n<td><span style=\"font-weight: 400\">The field will not be seen in the admin or any other ModelForm if False. They&#8217;re also left out of model validation. True is the default value.<\/span><\/td>\n<\/tr>\n<\/tbody>\n<\/table>\n<h5>Relationship Fields<\/h5>\n<p>Django additionally has a set of fields for representing relationships.<\/p>\n<table>\n<tbody>\n<tr>\n<td><b>Field Name<\/b><\/td>\n<td><b>Description<\/b><\/td>\n<\/tr>\n<tr>\n<td><b>Foreignkey<\/b><\/td>\n<td><span style=\"font-weight: 400\">It&#8217;s a one-to-many relationship. The class to which the model is connected, as well as the on delete option, are also required positional inputs.<\/span><\/td>\n<\/tr>\n<tr>\n<td><b>ManyToManyField<\/b><\/td>\n<td><span style=\"font-weight: 400\">There is a many-to-many relationship here. Requires a positional argument: the class to which the model is linked, which operates similarly to ForeignKey, including recursive and lazy relationships.<\/span><\/td>\n<\/tr>\n<tr>\n<td>&nbsp;<\/p>\n<p><b>OneToOneField<\/b><\/td>\n<td><span style=\"font-weight: 400\">It&#8217;s a one-on-one situation. This is comparable to a ForeignKey with unique=True in terms of concept, but the &#8220;reverse&#8221; side of the relation will yield a single object.<\/span><\/td>\n<\/tr>\n<\/tbody>\n<\/table>\n<h4>Step 5: Making Migrations<\/h4>\n<p>With the above steps, we have created a model. Let\u2019s add this to our database.<\/p>\n<p>Execute the following steps,<\/p>\n<pre class=\"EnlighterJSRAW\" data-enlighter-language=\"generic\">python manage.py makemigrations<\/pre>\n<p>You will see a new file named \u20180001_initial.py\u2019 under migrations.<\/p>\n<p><a href=\"https:\/\/techvidvan.com\/tutorials\/wp-content\/uploads\/sites\/2\/2021\/07\/Step_5.png\"><img loading=\"lazy\" decoding=\"async\" class=\"aligncenter size-full wp-image-83616\" src=\"https:\/\/techvidvan.com\/tutorials\/wp-content\/uploads\/sites\/2\/2021\/07\/Step_5.png\" alt=\"Django Models\" width=\"269\" height=\"650\" \/><\/a><\/p>\n<p>SQL Query has created the above model as a Table.<\/p>\n<p>Then, execute this command.<\/p>\n<pre class=\"EnlighterJSRAW\" data-enlighter-language=\"generic\">python manage.py migrate\n<\/pre>\n<p>With this, your new model is added to the database. Let\u2019s have a look at how Django uses the model to generate SQL.<\/p>\n<p>Write the following command in the terminal,<\/p>\n<pre class=\"EnlighterJSRAW\" data-enlighter-language=\"generic\">python manage.py sqlmigrate Employee 0001<\/pre>\n<p>You will come across an output like this:<\/p>\n<p><a href=\"https:\/\/techvidvan.com\/tutorials\/wp-content\/uploads\/sites\/2\/2021\/07\/Step_5_2.png\"><img loading=\"lazy\" decoding=\"async\" class=\"aligncenter size-full wp-image-83617\" src=\"https:\/\/techvidvan.com\/tutorials\/wp-content\/uploads\/sites\/2\/2021\/07\/Step_5_2.png\" alt=\"Django Models Output\" width=\"1384\" height=\"282\" \/><\/a><\/p>\n<h4>Step 6: Open the DB Browser (SQLite)<\/h4>\n<p><a href=\"https:\/\/techvidvan.com\/tutorials\/wp-content\/uploads\/sites\/2\/2021\/07\/Step_6.png\"><img loading=\"lazy\" decoding=\"async\" class=\"aligncenter size-full wp-image-83618\" src=\"https:\/\/techvidvan.com\/tutorials\/wp-content\/uploads\/sites\/2\/2021\/07\/Step_6.png\" alt=\"Open Django DB Model\" width=\"1920\" height=\"1018\" \/><\/a><\/p>\n<p>Now click on the \u2018Open Database\u2019 and move to the directory where you have saved your Project (TechVidvan2). Select the <strong>\u2018db.sqlite3\u2019.<\/strong><\/p>\n<p>So, this is the newly created table.<\/p>\n<p><a href=\"https:\/\/techvidvan.com\/tutorials\/wp-content\/uploads\/sites\/2\/2021\/07\/Step_6_2.png\"><img loading=\"lazy\" decoding=\"async\" class=\"aligncenter size-full wp-image-83619\" src=\"https:\/\/techvidvan.com\/tutorials\/wp-content\/uploads\/sites\/2\/2021\/07\/Step_6_2.png\" alt=\"Table in Django Models\" width=\"1920\" height=\"1030\" \/><\/a><\/p>\n<h3>Advantages Of\u00a0 Django Models<\/h3>\n<p>As we have discussed earlier, a model is a link between the server and the database. These are some of the advantages of models in Django:<\/p>\n<ul>\n<li><strong>Simplicity:<\/strong> Using Python is not only much easier than SQL, but it is also less error-prone.<\/li>\n<li><strong>Explicit description:<\/strong> The application has to know something about the database structure that is put in use. Django provided an explicit description of the data in the application code.<\/li>\n<li>Admin panel to create, update, delete or retrieve fields of a model.<\/li>\n<li>Version control<\/li>\n<li>Advanced Metadata<\/li>\n<\/ul>\n<h3>Built-in support for almost all the databases<\/h3>\n<p>Django provides a \u201cBatteries included\u201d approach. With Django, we can use any Relational database. We can even use cloud databases with Django, which is still lacking in many web frameworks out in the market.<\/p>\n<h3>Summary<\/h3>\n<p>This tutorial covered Django\u2019s model in more depth and created our first Django model. We have also used the SQLite database. We discussed the advantages of the model, and have also seen how the Django models are different.<br \/>\nIf you have any queries, feel free to comment down below.<\/p>\n","protected":false},"excerpt":{"rendered":"<p>In our previous article on Django\u2019s MVT architecture, we have done an overview of what Django models are. Till now we know that models are useful for storing and maintaining data in the database.&#46;&#46;&#46;<\/p>\n","protected":false},"author":1,"featured_media":83609,"comment_status":"open","ping_status":"closed","sticky":false,"template":"","format":"standard","meta":{"footnotes":""},"categories":[3383],"tags":[4007,4008,4009,4010],"class_list":["post-83394","post","type-post","status-publish","format-standard","has-post-thumbnail","hentry","category-django","tag-advantages-of-django-models","tag-create-your-first-django-model","tag-django-model-fields","tag-django-models"],"yoast_head":"<!-- This site is optimized with the Yoast SEO plugin v27.7 - https:\/\/yoast.com\/product\/yoast-seo-wordpress\/ -->\n<title>Django Models and the Steps to Create Your First Model - TechVidvan<\/title>\n<meta name=\"description\" content=\"Model in Django is an object that is saved in database. Learn about Django Models, its advantages &amp; steps to create your own django model.\" \/>\n<meta name=\"robots\" content=\"index, follow, max-snippet:-1, max-image-preview:large, max-video-preview:-1\" \/>\n<link rel=\"canonical\" href=\"https:\/\/techvidvan.com\/tutorials\/django-models-and-the-steps-to-create-your-first-model\/\" \/>\n<meta property=\"og:locale\" content=\"en_US\" \/>\n<meta property=\"og:type\" content=\"article\" \/>\n<meta property=\"og:title\" content=\"Django Models and the Steps to Create Your First Model - TechVidvan\" \/>\n<meta property=\"og:description\" content=\"Model in Django is an object that is saved in database. Learn about Django Models, its advantages &amp; steps to create your own django model.\" \/>\n<meta property=\"og:url\" content=\"https:\/\/techvidvan.com\/tutorials\/django-models-and-the-steps-to-create-your-first-model\/\" \/>\n<meta property=\"og:site_name\" content=\"TechVidvan\" \/>\n<meta property=\"article:publisher\" content=\"https:\/\/www.facebook.com\/TechVidvan\/\" \/>\n<meta property=\"article:published_time\" content=\"2021-08-11T03:30:01+00:00\" \/>\n<meta property=\"og:image\" content=\"https:\/\/techvidvan.com\/tutorials\/wp-content\/uploads\/2021\/07\/Models-in-Django.jpg\" \/>\n\t<meta property=\"og:image:width\" content=\"1200\" \/>\n\t<meta property=\"og:image:height\" content=\"628\" \/>\n\t<meta property=\"og:image:type\" content=\"image\/jpeg\" \/>\n<meta name=\"author\" content=\"TechVidvan Team\" \/>\n<meta name=\"twitter:card\" content=\"summary_large_image\" \/>\n<meta name=\"twitter:creator\" content=\"@vidvantech\" \/>\n<meta name=\"twitter:site\" content=\"@vidvantech\" \/>\n<meta name=\"twitter:label1\" content=\"Written by\" \/>\n\t<meta name=\"twitter:data1\" content=\"TechVidvan Team\" \/>\n\t<meta name=\"twitter:label2\" content=\"Est. reading time\" \/>\n\t<meta name=\"twitter:data2\" content=\"11 minutes\" \/>\n<!-- \/ Yoast SEO plugin. -->","yoast_head_json":{"title":"Django Models and the Steps to Create Your First Model - TechVidvan","description":"Model in Django is an object that is saved in database. Learn about Django Models, its advantages & steps to create your own django model.","robots":{"index":"index","follow":"follow","max-snippet":"max-snippet:-1","max-image-preview":"max-image-preview:large","max-video-preview":"max-video-preview:-1"},"canonical":"https:\/\/techvidvan.com\/tutorials\/django-models-and-the-steps-to-create-your-first-model\/","og_locale":"en_US","og_type":"article","og_title":"Django Models and the Steps to Create Your First Model - TechVidvan","og_description":"Model in Django is an object that is saved in database. Learn about Django Models, its advantages & steps to create your own django model.","og_url":"https:\/\/techvidvan.com\/tutorials\/django-models-and-the-steps-to-create-your-first-model\/","og_site_name":"TechVidvan","article_publisher":"https:\/\/www.facebook.com\/TechVidvan\/","article_published_time":"2021-08-11T03:30:01+00:00","og_image":[{"width":1200,"height":628,"url":"https:\/\/techvidvan.com\/tutorials\/wp-content\/uploads\/2021\/07\/Models-in-Django.jpg","type":"image\/jpeg"}],"author":"TechVidvan Team","twitter_card":"summary_large_image","twitter_creator":"@vidvantech","twitter_site":"@vidvantech","twitter_misc":{"Written by":"TechVidvan Team","Est. reading time":"11 minutes"},"schema":{"@context":"https:\/\/schema.org","@graph":[{"@type":"Article","@id":"https:\/\/techvidvan.com\/tutorials\/django-models-and-the-steps-to-create-your-first-model\/#article","isPartOf":{"@id":"https:\/\/techvidvan.com\/tutorials\/django-models-and-the-steps-to-create-your-first-model\/"},"author":{"name":"TechVidvan Team","@id":"https:\/\/techvidvan.com\/tutorials\/#\/schema\/person\/e9c26e74dd3d87421f7ada9433b8cd22"},"headline":"Django Models and the Steps to Create Your First Model","datePublished":"2021-08-11T03:30:01+00:00","mainEntityOfPage":{"@id":"https:\/\/techvidvan.com\/tutorials\/django-models-and-the-steps-to-create-your-first-model\/"},"wordCount":1956,"commentCount":0,"publisher":{"@id":"https:\/\/techvidvan.com\/tutorials\/#organization"},"image":{"@id":"https:\/\/techvidvan.com\/tutorials\/django-models-and-the-steps-to-create-your-first-model\/#primaryimage"},"thumbnailUrl":"https:\/\/techvidvan.com\/tutorials\/wp-content\/uploads\/2021\/07\/Models-in-Django.jpg","keywords":["Advantages of Django Models","Create Your First Django Model","Django Model Fields","Django Models"],"articleSection":["Django Tutorials"],"inLanguage":"en-US","potentialAction":[{"@type":"CommentAction","name":"Comment","target":["https:\/\/techvidvan.com\/tutorials\/django-models-and-the-steps-to-create-your-first-model\/#respond"]}]},{"@type":"WebPage","@id":"https:\/\/techvidvan.com\/tutorials\/django-models-and-the-steps-to-create-your-first-model\/","url":"https:\/\/techvidvan.com\/tutorials\/django-models-and-the-steps-to-create-your-first-model\/","name":"Django Models and the Steps to Create Your First Model - TechVidvan","isPartOf":{"@id":"https:\/\/techvidvan.com\/tutorials\/#website"},"primaryImageOfPage":{"@id":"https:\/\/techvidvan.com\/tutorials\/django-models-and-the-steps-to-create-your-first-model\/#primaryimage"},"image":{"@id":"https:\/\/techvidvan.com\/tutorials\/django-models-and-the-steps-to-create-your-first-model\/#primaryimage"},"thumbnailUrl":"https:\/\/techvidvan.com\/tutorials\/wp-content\/uploads\/2021\/07\/Models-in-Django.jpg","datePublished":"2021-08-11T03:30:01+00:00","description":"Model in Django is an object that is saved in database. Learn about Django Models, its advantages & steps to create your own django model.","breadcrumb":{"@id":"https:\/\/techvidvan.com\/tutorials\/django-models-and-the-steps-to-create-your-first-model\/#breadcrumb"},"inLanguage":"en-US","potentialAction":[{"@type":"ReadAction","target":["https:\/\/techvidvan.com\/tutorials\/django-models-and-the-steps-to-create-your-first-model\/"]}]},{"@type":"ImageObject","inLanguage":"en-US","@id":"https:\/\/techvidvan.com\/tutorials\/django-models-and-the-steps-to-create-your-first-model\/#primaryimage","url":"https:\/\/techvidvan.com\/tutorials\/wp-content\/uploads\/2021\/07\/Models-in-Django.jpg","contentUrl":"https:\/\/techvidvan.com\/tutorials\/wp-content\/uploads\/2021\/07\/Models-in-Django.jpg","width":1200,"height":628,"caption":"Models in Django"},{"@type":"BreadcrumbList","@id":"https:\/\/techvidvan.com\/tutorials\/django-models-and-the-steps-to-create-your-first-model\/#breadcrumb","itemListElement":[{"@type":"ListItem","position":1,"name":"Home","item":"https:\/\/techvidvan.com\/tutorials\/"},{"@type":"ListItem","position":2,"name":"Django Models and the Steps to Create Your First Model"}]},{"@type":"WebSite","@id":"https:\/\/techvidvan.com\/tutorials\/#website","url":"https:\/\/techvidvan.com\/tutorials\/","name":"TechVidvan Blogs","description":"","publisher":{"@id":"https:\/\/techvidvan.com\/tutorials\/#organization"},"potentialAction":[{"@type":"SearchAction","target":{"@type":"EntryPoint","urlTemplate":"https:\/\/techvidvan.com\/tutorials\/?s={search_term_string}"},"query-input":{"@type":"PropertyValueSpecification","valueRequired":true,"valueName":"search_term_string"}}],"inLanguage":"en-US"},{"@type":"Organization","@id":"https:\/\/techvidvan.com\/tutorials\/#organization","name":"TechVidvan","url":"https:\/\/techvidvan.com\/tutorials\/","logo":{"@type":"ImageObject","inLanguage":"en-US","@id":"https:\/\/techvidvan.com\/tutorials\/#\/schema\/logo\/image\/","url":"https:\/\/techvidvan.com\/tutorials\/wp-content\/uploads\/2024\/03\/techvidvan-logo-200x50-1.webp","contentUrl":"https:\/\/techvidvan.com\/tutorials\/wp-content\/uploads\/2024\/03\/techvidvan-logo-200x50-1.webp","width":200,"height":50,"caption":"TechVidvan"},"image":{"@id":"https:\/\/techvidvan.com\/tutorials\/#\/schema\/logo\/image\/"},"sameAs":["https:\/\/www.facebook.com\/TechVidvan\/","https:\/\/x.com\/vidvantech"]},{"@type":"Person","@id":"https:\/\/techvidvan.com\/tutorials\/#\/schema\/person\/e9c26e74dd3d87421f7ada9433b8cd22","name":"TechVidvan Team","description":"The TechVidvan Team delivers practical, beginner-friendly tutorials on programming, Java, Python, C++, DSA, AI, ML, data Science, Android, Flutter, MERN, Web Development, and technology. Our experts are here to help you upskill and excel in today\u2019s tech industry."}]}},"amp_enabled":true,"_links":{"self":[{"href":"https:\/\/techvidvan.com\/tutorials\/wp-json\/wp\/v2\/posts\/83394","targetHints":{"allow":["GET"]}}],"collection":[{"href":"https:\/\/techvidvan.com\/tutorials\/wp-json\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/techvidvan.com\/tutorials\/wp-json\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/techvidvan.com\/tutorials\/wp-json\/wp\/v2\/users\/1"}],"replies":[{"embeddable":true,"href":"https:\/\/techvidvan.com\/tutorials\/wp-json\/wp\/v2\/comments?post=83394"}],"version-history":[{"count":0,"href":"https:\/\/techvidvan.com\/tutorials\/wp-json\/wp\/v2\/posts\/83394\/revisions"}],"wp:featuredmedia":[{"embeddable":true,"href":"https:\/\/techvidvan.com\/tutorials\/wp-json\/wp\/v2\/media\/83609"}],"wp:attachment":[{"href":"https:\/\/techvidvan.com\/tutorials\/wp-json\/wp\/v2\/media?parent=83394"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/techvidvan.com\/tutorials\/wp-json\/wp\/v2\/categories?post=83394"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/techvidvan.com\/tutorials\/wp-json\/wp\/v2\/tags?post=83394"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}