# Integrating Dagster with Django

**URL:** https://discuss.dataengineercafe.io/t/integrating-dagster-with-django/69
**Category:** Dagster
**Tags:** django
**Created:** [December 16, 2021, 7:45am UTC](https://discuss.dataengineercafe.io/t/integrating-dagster-with-django/69 "2021-12-16T07:45:33Z")
**Posts on this page:** 2
**Page:** 1

<div class="post-metadata">

### Author: ![zkan](https://yyz1.discourse-cdn.com/flex035/user_avatar/discuss.dataengineercafe.io/zkan/32/2_2.png) [@zkan](https://discuss.dataengineercafe.io/u/zkan)
#### Post date: [December 16, 2021, 7:45am UTC](https://discuss.dataengineercafe.io/t/integrating-dagster-with-django/69/1 "2021-12-16T07:45:33Z")

</div>

เมื่อปีที่แล้วเห็นคำถามนี้ใน Stack Overflow เลยไปตอบดู คิดว่าเอามาแชร์ในนี้ด้วยน่าจะมีประโยชน์เผื่อใครแวะเข้ามาครับผม

> <https://stackoverflow.com/questions/59048161/integrating-dagster-with-django>

ด้านล่างนี้เป็นโค้ดที่ผมใช้ครับ

```auto
import os
import sys

import django
from dagster import execute_pipeline, pipeline, solid

# Add the project to sys.path, so that Python can find packages
PROJECT_ROOT = os.path.join(os.path.dirname( __file__ ), 'demo')
sys.path.append(PROJECT_ROOT)

# Set up the Django environment
os.environ.setdefault('DJANGO_SETTINGS_MODULE', 'demo.settings')
django.setup()

from customers.models import Customer

@solid
def hello_django_orm(context):
    number_of_customers = Customer.objects.count()
    message = f'Found {number_of_customers} customers!'
    context.log.info(message)
    return number_of_customers

@pipeline
def hello_django_orm_pipeline():
    hello_django_orm()

if __name__ == ' __main__':
    result = execute_pipeline(hello_django_orm_pipeline)
    assert result.success

```

**Ref:** [hello-dagster/hello\_django\_orm.py at main · zkan/hello-dagster · GitHub](https://github.com/zkan/hello-dagster/blob/main/dagster-with-django-orm/hello_django_orm.py)

---

<div class="post-metadata">

### Author: ![zkan](https://yyz1.discourse-cdn.com/flex035/user_avatar/discuss.dataengineercafe.io/zkan/32/2_2.png) [@zkan](https://discuss.dataengineercafe.io/u/zkan)
#### Post date: [December 16, 2021, 11:48am UTC](https://discuss.dataengineercafe.io/t/integrating-dagster-with-django/69/2 "2021-12-16T11:48:06Z")

</div>

**หมายเหตุไว้สักหน่อย** โค้ดที่ใช้ด้านบนเป็นโค้ด Dagster เวอร์ชั่นเก่านะครับ

ตอนนี้เค้าเปลี่ยนคอนเซป และเปลี่ยนจากคำว่า `solid` ไปเป็นคำว่า `ops` เปลี่ยน `pipeline` ไปเป็น `graph` แล้ว~
