Author: saqibkhan

  • Update Model

    Django’s ORM API provides useful functionality for performing CRUD operations on the data stored in the tables of relational databases. The create(), update() and delete() methods perform their respective operations on an already existing table. However, you often need to make changes to the model structure itself, by adding, deleting or altering the attributes of the model. Django’s admin…

  • Update Data

    Django ORM uses the Active Record pattern for the interaction between a model class and its mapped database table. An instance of the model class corresponds to a single row in the table. Any of the attributes of the object results in updating the corresponding row. In this chapter, we will focus on the different…

  • Insert Data

    Django has its own Object Relation Model (ORM) that maps a Python class with a table in a relational database. The ORM mechanism helps in performing CRUD operations in object-oriented manner. In this chapter, we shall learn about different methods of inserting a new data. By default, Django uses a SQLite database. A model in…

  • Models

    A model is a class that represents table or collection in our DB, and where every attribute of the class is a field of the table or collection. Models are defined in the app/models.py (in our example: myapp/models.py) Creating a Model Following is a Dreamreal model created as an example − Every model inherits from…

  • Update Objects

    Once a model is registered with Django’s Admin app, we can easily perform CRUD operations on the model. In the previous chapter, we learned to register the Employee model. The homepage of admin site shows it under the MYAPP section − Display The List of Objects To display the list of objects, click on the name − Add…

  • Set Fields to Display

    When a model is registered to Django’s Admin site, its list of objects is displayed when you click the name of the model. In the following figure, the list of objects in the Employees model is displayed − However, the above page shows the objects in the form Employee object(1), which doesn’t reveal the attributes such as…

  • Include Models

    When a new project is initialized with the startproject command, Django automatically installs a few apps, the list of these apps can be found in the INSTALLED_APPS parameter of the project’s settings module. To be able to log into the admin site, the models – Groups and Users are automatically registered with the Admin site. Hence, as…

  • Create User

    The Django framework readily provides a robust user management system. The users, groups, and permissions are managed both through the admin interface as well as programmatically. When you create a new project with the startproject command, the admin and auth apps are added in the INSTALLED_APPS by default. All the user objects are stored in the “django.contrib.auth.models.User” model. Assuming that the project…

  • Admin Interface

    Django provides a ready-to-use user interface for administrative activities. We all know how an admin interface is important for a web project. Django automatically generates admin UI based on your project models. Starting the Admin Interface The Admin interface depends on the django.countrib module. To have it working you need to make sure some modules…

  • Add Master Template

    Django supports template inheritance. The concept of inheritance in Django is very similar to inheritance in object-oriented programming. The idea is that the output rendered by each view in a web application must follow a uniform pattern or look, even though each view may render a different template. Suppose a Django app has three URL…