1

NB: I have already gone through the Django official documentation here docs.djangoproject.com/en/dev/topics/db/multi-db, but nothing on the page answers my questions.

I have led a team to develop two Django web applications and we have reached a stage where we would like to make features on each of the sites available to one another. By so doing, we would have adhered to the DRY principle.

Case Study

Site A has A+ features and i would love to make it available on site B, through Django Queryset, and vice versa.

So far

I have defined in the settings.py file for both sites the database configurations, added a generic Router configuration for all the apps with the help of this post: http://diegobz.net/2011/02/10/django-database-router-using-settings/ and can successfully query the databases for A and B from both sites using from django.db import connections. However, with the below:

def dictfetchall(cursor):
    "Returns all rows from a cursor as a dict"
    desc = cursor.description
    return[
        dict(zip([col[0] for col in desc], row))
        for row in cursor.fetchall()
        ]

i get lists of objects' data and not Querysets.

Question

  1. Is this the right away to go about the problem described above?
  2. Is there a way to import/return Querysets/iterable Model objects using the implementation described above?
  3. Are there APIs out there that can handle Django Multi-databases connection? If yes, please provide links?

Thank you for your time.

My Solution (for now)

It seems the strategy i was planning to use before was kind of an overkill. So, i decided to adopt a different strategy. However, it seems to get me half-way but i foresee it leading to DRY.

The solution is to have REST-APIs on both sites return data in json format.

i.e call API of site A, load the returned data and process it in site B.

Community
  • 1
  • 1
AJNinja
  • 140
  • 1
  • 15
  • Have you read this? https://docs.djangoproject.com/en/dev/topics/db/multi-db/ – dfranca Sep 16 '14 at 09:31
  • Yes, i have. I'm not sure i would have been able to get this far without first going through the link you have provided. Meanwhile, nothing on the page answers my questions. Thanks – AJNinja Sep 16 '14 at 11:32

0 Answers0