def sync_model(self, model, only_latest=False):

        app_label = model._meta.app_label
        module_name = model._meta.module_name

        name_pair = [app_label, module_name]

        if self.verbosity > 1:
            print "Exporting %s.%s" % tuple(name_pair)

        qs = model.objects.all()

        # do we need only latest ?
        if only_latest:
            qs = qs[:self.LATEST_COUNT]
            if self.verbosity > 1:
                print "    Exporting only %d latest" % self.LATEST_COUNT

        counted = 0
        total = 0
        newobjs = []
        commit_every = 950 / len(model._meta.fields)

        for obj in qs.iterator():
            if counted > commit_every:
                if self.verbosity > 1:
                    print "    committed %d so far" % total

                model.objects.using(self.DB).bulk_create(newobjs)
                transaction.commit(using=self.DB)
                newobjs=[]
                counted = 0

            # obfuscate user data
            if name_pair == ['auth', 'user']:
                obj.set_unusable_password()
                uid = 'user_%s' % obj.pk
                obj.username = uid
                obj.first_name = uid
                obj.last_name = uid
                obj.email = '%s@example.com' % uid

            if name_pair == ['user', 'userprofile']:
                obj.description = u''
            newobjs.append(obj)

#            obj.save(using=self.DB)
            counted += 1
            total += 1

        # make sure everything is saved
        if newobjs:
            model.objects.using(self.DB).bulk_create(newobjs)

        transaction.commit(using=self.DB)
        print "    %d Exported" % total
Save model instances to the dev db
dataset/ETHPy150Open ofri/Open-Knesset/simple/management/commands/sync_dev.py/Command.sync_model