Django CRUD (Create, Retrieve, Update, Delete) Function Based Views:
- Create – create or add new entries in a table in the database.
- Retrieve – read, retrieve, search, or view existing entries as a list(List View) or retrieve a particular entry in detail (Detail View)
- Update – update or edit existing entries in a table in the database
- Delete – delete, deactivate, or remove existing entries in a table in the database
-
create the model
After creating this model, we need to run two commands in order to create Database for the same.
Python manage.py makemigrations
Python manage.py migrate
-
create form.py
-
Create View
Create View refers to a view (logic) to create an instance of a table in the database
-
Create a template in templates/create_view.html
-
Retrieve View
Retrieve view is basically divided into two types of views Detail View and List View.
List View
List View refers to a view (logic) to list all or particular instances of a table from the database in a particular order. It is used to display multiple types of data on a single page or view
-
Create a template in templates/list_view.html
- Detail View
Detail View refers to a view (logic) to display a particular instance of a table from the database with all the necessary details. It is used to display multiple types of data on a single page or view, for example, profile of a user.
-
create a view and template for the same. In geeks/views.py
- Create a template in templates/Detail_view.html
- Update View
Update View refers to a view (logic) to update a particular instance of a table from the database with some extra details. It is used to update entries in the database for example, updating an article at geeksforgeeks.
- Delete View
Delete View refers to a view (logic) to delete a particular instance of a table from the database. It is used to delete entries in the database for example,In views.py
Template for delete view includes a simple form confirming whether user wants to delete the instance or not. In templates/delete_view.html,