簡體   English   中英

如何使用與同一數據庫交互的外部 python 包構建 Django 項目

[英]How to structure Django project with external python packages interacting with the same database

我正在開發一個 Django Rest Api ,我的目標是以下結構:

django_project
│-- django_project
    │--__init.py__
    │-- asgi.py
    │-- setting.py
    │-- urls.py
    │-- wsgi.py
│-- app
    │-- migrations
    │-- __init.py__
    │-- admin.py
    │-- apps.py
    │-- models.py
    │-- tests.py
    │-- views.py
│-- manage.py
│-- media
│-- static
│-- templates

問題是我想包括一個我為數據處理開發的外部 python package。 這個 package 使用 slqalchemy 進行數據庫映射,所以我不確定如何(以及在何處)將其放入我的 django 項目中,因為會有重復的模型定義(使用 sqlachemy 和 Djando ORM)。

謝謝你的幫助

您可以根據需要添加任意數量的應用程序:

django_project
│-- django_project
    │--__init.py__
    │-- asgi.py
    │-- setting.py
    │-- urls.py
    │-- wsgi.py
│-- app_1
    │-- migrations
    │-- __init.py__
    │-- admin.py
    │-- apps.py
    │-- models.py
    │-- tests.py
    │-- views.py
│-- app_2
    │-- __init.py__
    │-- admin.py

 ...

│-- manage.py
│-- media
│-- static
│-- templates

Actually django app can be with or without django orm models.You don't have to register python package as app at settings to import and use it in other registered apps. Registration python package as django app is needed if we develop django orm models and use migrations, or have signals, or celery tasks, or urls.

暫無
暫無

聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.

 
粵ICP備18138465號  © 2020-2024 STACKOOM.COM