[Answer]-Sync Data between SAP and DataModels in Django

1đź‘Ť

âś…

There’s really no “best method for data syncing” in Django.

Really, this is all about how you design your data models.

A few tips:

  1. Figure out your source systems unique identifier for each object. Usually this is just something like “id” or whatever.
  2. Always, always, store a created and modified date on your models. This will make sync easier. I usually do it like so:

    created_on = models.DateTimeField('Created On', auto_now_add=True)
    last_modified = models.DateTimeField('Last Modified', auto_now=True)
    
  3. With those two bits in place (and all the other fields you need to store), it’s just a matter or writing code which will retrieve all the records from the source system and check them against the records you have. This will be a tedious process, and completely manual. There is no “django-magic-model-sync” thing for this type of project. Just the hard work of fetching the records from the source, checking them against your data store, and updating what needs to be updated.

  4. You’ll probably want to use Celery, since I imagine you’ll want to do this sync every X minutes, or hours, or days, or whatever. So you’ll want to write a Celery task which does #3.
👤Jack Shedd

0đź‘Ť

u can use Django with multiple databases .

DATABASES = {
    'default': {
        'NAME': 'app_data',
        'ENGINE': 'django.db.backends.postgresql_psycopg2',
        'USER': 'postgres_user',
        'PASSWORD': 's3krit'
    },
    'items': {
        'NAME': 'items_data',
        'ENGINE': 'django.db.backends.mysql',# or what ever Engine 
        'USER': 'mysql_user',
        'PASSWORD': 'priv4te'
    }

}

and you can sync the dedicated db only .

./manage.py syncdb --database=items

in your models you can use like Eg:

Items.objects.using('items').all()
👤Anish Menon

Leave a comment