Python Backend Logic Adding MVC Framework (Django)

I have a Python CLI program with SQL database models and want to add an interface with an MVC framework (like Django). What is the best way to link my program to the framework if I have already defined my models?

I also:

  • Rewrite the model so that it shares with both Django and my program
  • Write a layer that interacts between Django and my program.
  • Remove the model from My Program and let Django handle it

Choice # 1: General Model

          My Program
        /      |    \
  Binaries    Model  Classes
               |
             Django
             /    \
         View     Controller

Option # 2: creating a bridge library

          My Program
        /      |    \
  Binaries    Model  Classes
               |
            My-Bridge
               |
             Django
             / |    \
         View  Model Controller

Choice # 3: using Django for most jobs and removing the model from my program

  Classes
         \
          My Program
        /      | 
  Binaries     |
               |
            My-Bridge
               |
             Django
             /   |    \
         View   Model   Controller

I avoid choosing No. 1 (creating a generic model) because I don't know how to create a generic model using Django ORM and SQLAlchemy.

№ 2 ( ), , Django . , Django , MVC.

№ 3 ( ), ORM SQLAlchemy, SQLAlchemy My-Program.

, , ? , CLI?

+3
4

Django, , , Pylons, SQLAlchemy. SQLAlchemy, . . .

+3

, , , . , , . , . ORM ORM .

ORM, , .

, . ORM , .

+1

" " , . django . django grunt, " " . , , , .

0

Rewriting models according to django api sounds like the least amount of work and the most “right” way to solve your problem. If you are not using any kind of “advanced” access to the database, Djangos ORM should be able to handle what you want to do cleanly. Using the full stack also pays dividends later when you decide that you want the forms to wrap your models and all the other bits of the structure that expect the structure of the model.

0
source

Source: https://habr.com/ru/post/1783063/


All Articles