2

I have a system consisted of a few micro services that use each other. One of them is a Django server (let's name it A) and another is a python module that doesn't use Django at all (let's name it B).

My project structure looks something like this:

-root
  - commons
  - A
  - B

Where commons is used both in A and B and in deployment copied to each. B uses A via HTTP calls.

I would like in B to use the model objects of A instead of using them as dicts. What is the best practice for this?

I attempted to move the models.py file from A to commons and import it from there in both. I don't know if it will work for B yet, as it fails the tests of A with:

RuntimeError: Model class commons.models.A.SomeModel doesn't declare an explicit app_label and isn't in an application in INSTALLED_APPS.

I am using Django 1.10.3 and Python 3.5

EDIT: I am using DRF and my thoughts were once I get the response JSON via http use a serializer (move it to commons as well) to serialize the model objects and then I can use as objects with members and methods.

Thanks ahead,

Uri Shalit
  • 2,198
  • 2
  • 19
  • 29
  • How do you intend to use these models? – Alvaro Jan 23 '17 at 19:48
  • I want to use the classes as objects, I thought using both the models and serializers in B - use the serializer to create the objects from the Json. Then, I can access it's members and use it's functions – Uri Shalit Jan 23 '17 at 19:56
  • Does this help http://stackoverflow.com/a/34300942/2348704 ? – bhaskarc Jan 23 '17 at 20:23
  • Or this ? http://stackoverflow.com/questions/2180415/using-django-database-layer-outside-of-django – bhaskarc Jan 23 '17 at 20:46
  • What is the reason of making microservices if they share codebase? In my opinion it is poor design. If you need to do something asynchronously then it is better to use [celery](http://www.celeryproject.org/) instead of making additional http service. – Raz Jan 24 '17 at 08:44

0 Answers0