Skip to player
Skip to main content
Skip to footer
Search
Connect
Watch fullscreen
Like
Bookmark
Share
Add to Playlist
Report
How to create a Django's model and save data in database table
InterTuts
Follow
8/30/2024
In this video I'm showing how I'm creating a Django's model that handles posts for social sharing. I'm showing also how I'm saving the posts in the database using the created Django's model.
Category
🦄
Creativity
Transcript
Display full video transcript
00:00
In this video, I'll show how to create a Django model and store data within it.
00:10
My Django model is defined in the Posts app.
00:16
I use the Models.py file within the app to store the models' fields.
00:31
And this is my Django model for social posts.
00:40
This model extends the BaseModel class, which provides the core functionality needed to
00:52
define database models.
00:57
The ID field is an auto-incrementing primary key field, which is automatically included.
01:09
This field is a foreign key linking to the custom user model.
01:21
This means if this user is deleted, all its posts will be deleted too, and this user will
01:34
be used as the owner of the post.
01:39
This field is used to store the post text and this the post image.
01:49
Next, this field will contain the current date and time when the post is created.
02:02
This will contain the table name in the database, and this will return a piece of the post text
02:18
in the admin interface to represent the post.
02:25
To create the database table for this model, I need to use this li command.
02:43
And this.
02:49
My table is already created.
02:54
To create a post in my view file, I will call the posts model and will set the post data.
03:18
Finally, I will save.
03:22
Let's see a real example.
03:26
Now, I will create a post that should be saved in the database table.
03:52
And the post was created as expected.
Recommended
2:28
|
Up next
Pagination in React & Next JS
InterTuts
12/20/2024
1:47
React & Node.js Social Chat: unsubscribe Facebook Pages from application's webhook
InterTuts
12/18/2024
1:22
How to use notifications alerts in React & Next JS
InterTuts
12/18/2024
3:30
React & Node.js Social Chat: how to connect Facebook Pages to receive direct messages
InterTuts
12/18/2024
1:56
How to convert a string to MongoDB ObjectId in Node.js
InterTuts
12/17/2024
2:05
How to bulk insert or update data in MongoDb with Mongoose
InterTuts
12/16/2024
1:41
How to retrieve URL's query parameters in Next.js(CSR)
InterTuts
12/15/2024
3:27
How to handle dynamic route parameters in Express.js
InterTuts
12/14/2024
1:42
How to retrieve and pass dynamic route segment between components in Next.js & React
InterTuts
12/14/2024
2:00
How to create vertical tabs in Chakra UI
InterTuts
12/14/2024
1:53
How to create a modal in Chakra UI & React
InterTuts
12/13/2024
0:49
React & Node.js Social Chat: Introduction
InterTuts
12/11/2024
3:02
How to use recipes in Chakra UI & Next.JS
InterTuts
12/11/2024
1:33
How to setup global fonts in Chakra UI & Next.JS
InterTuts
12/10/2024
2:30
How to setup global colors in Chakra UI & Next.JS
InterTuts
12/10/2024
1:54
Serializing big strings impacts deserialization performance (consider using Buffer instead and decode when needed)
InterTuts
12/9/2024
1:46
Angular & ASP.NET Core Web API Authentication: how is working registration and sign in using Google API
InterTuts
12/7/2024
4:30
Angular & ASP.NET Core Web API Authentication: how is working registration
InterTuts
12/7/2024
5:10
Angular & ASP.NET Core Web API Authentication: how is working the password reset
InterTuts
12/7/2024
2:44
Angular & ASP.NET Core Web API Authentication: how is working remember me login
InterTuts
12/7/2024
4:37
Angular & ASP.NET Core Web API Authentication: how is working login
InterTuts
12/7/2024
4:48
How to validate an email address in ASP.NET Core Web API using a custom attribute
InterTuts
11/30/2024
3:29
How to reset a reactive form in Angular 19
InterTuts
11/29/2024
3:54
How to validate Angular Material reactive form in Angular 19
InterTuts
11/27/2024
2:12
How to test .http files with REST Client
InterTuts
11/25/2024