📝 Django

Bulk Operations in Django ORM

P
Author
PyLand Team
📅
Published
30.06.2026
⏱️
Reading time
1 min
👁️
Views
291
🌳
Level
Advanced

Covered topics: bulk_create — Mass Creation, bulk_update — Mass Update, update() — Queryset-Level Update, delete() — Queryset-Level Deletion.

bulk_create — Mass Creation

tasks = [
    Task(title='Task 1', status='todo'),
    Task(title='Task 2', status='todo'),
    Task(title='Task 3', status='in_progress'),
]
Task.objects.bulk_create(tasks)
# One SQL INSERT instead of three

bulk_update — Mass Update

tasks = Task.objects.filter(status='todo')
for task in tasks:
    task.priority = 5

Task.objects.bulk_update(tasks, ['priority'])
# One SQL UPDATE instead of N

update() — Queryset-Level Update

# Update the status of all overdue tasks
Task.objects.filter(due_date__lt=today, status='todo').update(status='overdue')

delete() — Queryset-Level Deletion

# Delete all completed tasks older than 30 days
Task.objects.filter(status='done', updated_at__lt=threshold).delete()

Performance Comparison

Method 1000 objects SQL queries
Loop save() slow 1000
bulk_create() fast 1
update() very fast 1

Limitations of bulk_create

  • Does not call save() or signals
  • Does not update auto_now fields by default
  • Supports update_conflicts=True for PostgreSQL
Task.objects.bulk_create(
    tasks,
    update_conflicts=True,
    unique_fields=['title'],
    update_fields=['status', 'priority'],
)

Your reaction to the article

💬 Comments (0)

🔐 Sign in to leave a comment
🚪 Login
💭

No comments yet

Be the first to share your opinion about this article!

🔗 Similar

Similar articles

Continue learning with these materials

📝

Search in Django

You can start with simple Django ORM filters and move to PostgreSQL features when you...

📅 30.06.2026 👁️ 280
📝

Swagger Documentation with drf-spectacular

drf-spectacular generates an OpenAPI 3.0 schema and Swagger UI for DRF.

📅 30.06.2026 👁️ 565
📝

settings.py: Django Configuration

settings.py is the central configuration file for a Django project.

📅 30.06.2026 👁️ 316

Did you like the article?

Subscribe to our updates and be the first to receive new articles. Grow with PyLand!