Question

Now I'm developing an application under Django, it's an ERP for WareHouse Management. And the main application is made with SAP Bussiness One. I have access to tables in SAP (MSSQL Server), but I need build WareHouse Management using Table ITEMs in SAP inside DJANGO dataModel table, for instance: I need sync my DataModel Table Items in Django with Table ITEMs SAP , not reverse (DJANGO -> ITEM's in SAP [NO!]).

What is the best method for sync DataModels in Django with other Databases systems or tables?

I'd like to maintain consistency in Django Databases, because if in Item's table in SAP, change something, for instance Item Active (true or false) this change will be reflected in Django Models.

So, If there is a new Item in SAP Table, it must be in Django DataModel Table.

I'm trying simple Django Model, to maintain this:

class Items(models.Model):
    SapCode         =models.CharField(max_length=100)
    Name            =models.CharField(max_length=250)
    Group           =models.IntegerField()
    Active          =models.BooleanField()

I just only track changes in:

  • New Items (new Code)

  • Changes in Name.

  • Changes in Group.

  • Change status in Active

Thanks in advance!.

Était-ce utile?

La solution

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.

Autres conseils

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()
Licencié sous: CC-BY-SA avec attribution
Non affilié à StackOverflow
scroll top