def form_valid(self, form): context = self.get_context_data(form=form) self.object = form.save(commit=False) for part in self.parts: if part.is_valid() and part.has_changed(): part.save() if part.rows.is_valid() and part.instance.pk: part.rows.save() if self.parts.is_valid(): self.parts.save() self.object.amount = sum(r.instance.out or 0 for r in self.parts) self.object.tto = list(set((convert_tto(','.join(r.instance.tto or '' for r in self.parts))))) self.object.save() if all(p.is_valid() and p.rows.is_valid() for p in self.parts): messages.success(self.request, u'Партия сохранена успешно!') return redirect(self.get_success_url()) return self.render_to_response(context)
def get_tto(self): return convert_tto(self.tto)
def get_limestone_tto(self): if self.limestone: return convert_tto(self.limestone) else: return []
def get_tto(self): return sorted(set(convert_tto(self.tto)))