L
L
LXSTVAYNE2022-03-30 11:39:26
Django
LXSTVAYNE, 2022-03-30 11:39:26

How to correctly use django models in two projects?

It is planned to raise two containers on the server with a common database. The first is an asynchronous telegram bot, the second is a django web application. The web application has models, how to properly embed them in the bot?

What he did: he prescribed similar models for the bot and referred to the same table. What I don’t like about this approach: the DRY principle is violated, in order to use it in asynchronous handlers, you need to wrap each request in sync_to_async.
There is an idea to use an asynchronous ORM in a bot, like tortoise, if this is, of course, possible. However, the DRY principle is also violated. But if you think about it, then the containers should not know about each other ...

Maybe I'm wrong and you should use my idea and not think about DRY, or is it better to use some other option?

Answer the question

In order to leave comments, you need to log in

1 answer(s)
I
i3a4em, 2022-03-30
@i3a4em

I'm currently working on a similar project. All asynchronous work, on the advice of experts, was taken out into a separate microservice. At the moment, I pack all the data needed by the microservice in json and upload it to redis. The microservice reads redis in a loop and writes the results there, and django deserializes them and writes them to postgres (if required). One of these days I plan to move to kafka + debezium (as soon as I figure it out). I guess that's what you need for this kind of task. But even now I am very pleased with the result.
It was discussed here
And I recommend that you familiarize yourself with the kafka + debezium bundle

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question