📝 Django

Bulk Operations in Django ORM

P
Author
Pyland
📅
Published
30.06.2026
⏱️
Reading time
1 min
👁️
Views
73
🌳
Level
Advanced

Охватываемые темы: 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

📝

pytest-django: Testing Django

Охватываемые темы: Installation, @pytest.mark.djangodb, Fixtures, Testing views.

📅 30.06.2026 👁️ 138
📝

Django: Template Tags

Template tags are logic inside HTML. Unlike {{ variable }} which only outputs a value,...

📅 30.06.2026 👁️ 85
📝

Django: Static Files

Static files are CSS, JavaScript, images, and fonts. Django handles them in a specific way:...

📅 30.06.2026 👁️ 77

Did you like the article?

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