Python Django

How To Create And Use Custom Model Managers In Django

We all know that model data operation in Django is so easy, you do not need to write any sql command at all, what you need to do is just use model class’s attribute objects ‘s methods to create, query, update and delete mode data records in backend database table like below. Suppose our model […]

How To Create And Use Custom Model Managers In Django Read More »

How To Force Reset Django Models Migrations

During the process of developing the example code in the article Django Bootstrap3 Example, when I change the model class source code ( for example add a new field ), I always want to migrate the changes to the backend database table immediately. But I found sometimes the migration does not take effect when the

How To Force Reset Django Models Migrations Read More »

How To Operate Foreign Key And Many To Many Field In Django Model

This example is based on the article Django Bootstrap3 Example, it reuse the Department and Employee model class. Suppose Department and Employee model are many to many relationships, that means one department can have multiple employees and one employee can belong to multiple departments. Then we need to do the following changes.

How To Operate Foreign Key And Many To Many Field In Django Model Read More »

How To Show Custom Model Columns Using Django Admin

In the previous article How To Add Models To Django Admin Site, we have learned how to manage your Django app’s model data in the Django project admin website. But even we implement the model class’s __str__(self) function, we can only display one model class column in the project admin site like the below picture.

How To Show Custom Model Columns Using Django Admin Read More »

How To Add Models To Django Admin Site

When you create a Django project and start the project built-in web server successfully, it also contains an admin website in this project. This admin website is the result of django.contrib.admin and django.contrib.auth Django applications. The Django project installed some default applications in the project settings.py file when you create it. You can find them in the INSTALLED_APPS section

How To Add Models To Django Admin Site Read More »

How To Show SQL Query Command In Django Migration

Django model class is defined in models.py file in Django application folder, each model class will be mapped to a database table in the project backend database server. After you define the model class, you can create the related table use Django manage.py tasks command, all the low level sql command ( such as table

How To Show SQL Query Command In Django Migration Read More »

How To Pass Multiple Parameters Via Url In Django

If you find the Django url pattern is not easy to use when you want to pass multiple request parameters via url, you can use the original method to implement it. The original method is to use url like this http://127.0.0.1:8000/dept_emp/emp_list/?dept_id=1&user_name=jerry. It just adds the parameter name and value pair after the question mark (?) of

How To Pass Multiple Parameters Via Url In Django Read More »