<SYSTEM_TASK:>
Solve the following problem using Python, implementing the functions described below, one line at a time
<END_TASK>
<USER_TASK:>
Description:
 def save(self):
 """Saves all model instances in the batch as model. """

        saved = 0
        if not self.objects:
            raise BatchError("Save failed. Batch is empty")
        for deserialized_tx in self.objects:
            try:
                self.model.objects.get(pk=deserialized_tx.pk)
            except self.model.DoesNotExist:
                data = {}
                for field in self.model._meta.get_fields():
                    try:
                        data.update({field.name: getattr(deserialized_tx, field.name)})
                    except AttributeError:
                        pass
                self.model.objects.create(**data)
                saved += 1
        return saved