def populate_obj(self, obj, name): model = self.unbound_field.args[0].Meta.model state = obj._sa_instance_state if not state.identity or self.population_strategy == 'replace': setattr(obj, name, []) for counter in xrange(len(self.entries)): try: self.pre_append_object(obj, name, counter) try: getattr(obj, name).append(model()) except AttributeError: pass except SkipOperation: pass else: for index, entry in enumerate(self.entries): data = entry.data try: if not has_entity(obj, name, model, data): getattr(obj, name).insert(index, model()) except UnknownIdentityException: # we should skip all entries which are not part of obj # collection self.entries.pop(index) FieldList.populate_obj(self, obj, name)
def populate_obj(self, obj, name): self.delete_existing(obj, name) model = self.unbound_field.args[0].Meta.model for counter in xrange(len(self.entries)): try: self.pre_append_object(obj, name, counter) try: getattr(obj, name).append(model()) except AttributeError: pass except SkipOperation: pass FieldList.populate_obj(self, obj, name)
def populate_obj(self, obj, name): state = obj._sa_instance_state if not state.identity or self.population_strategy == 'replace': setattr(obj, name, []) for counter in six.moves.range(len(self.entries)): try: getattr(obj, name).append(self.model()) except AttributeError: pass else: for index, entry in enumerate(self.entries): data = entry.data coll = getattr(obj, name) if find_entity(coll, self.model, data) is None: coll.insert(index, self.model()) FieldList.populate_obj(self, obj, name)