September 2019
Beginner to intermediate
494 pages
13h
English
Database objects in a Django project can also be accessed and modified in a Python script using various Django APIs. In this section, we will automate the process of populating our Post database table using this feature.
We will be making Python queries to our database table via the Python Console panel. To access it, go to View | Tool Windows | Python Console. Now, we will create a few Post objects in our database manually by entering in the following code, line by line:
>>> from django.contrib.auth.models import User>>> from blog.models import Post>>> user = User.objects.get(username='quannguyen') # replace with your username>>> for i in range(10):... post = Post.objects.create(... title=f'Automated post ...
Read now
Unlock full access