def form_valid(self, form): for key in self.request.POST: if key.find('id_attribute') != -1 and self.request.POST[key]: sample = self.object qualifier = Qualifier.objects.get(pk=key.split('_')[-1]) value = self.request.POST[key] sample_meta = SampleMeta.objects.filter(qualifier=qualifier, sample=sample) if sample_meta: sample_meta = sample_meta[0] sample_meta.value = value else: sample_meta = SampleMeta(sample=sample, qualifier=qualifier, value=value) sample_meta.save() return super(SampleUpdate, self).form_valid(form)
def form_valid(self, form): user = self.request.user form.instance.created_by = user # save sample self.object = form.save() # save sample meta for key in self.request.POST: if key.find('id_attribute') != -1 and self.request.POST[key]: sample = self.object qualifier = Qualifier.objects.get(pk=key.split('_')[-1]) value = self.request.POST[key] sample_meta = SampleMeta(sample=sample, qualifier=qualifier, value=value) sample_meta.save() # save log log_record = self.log_model(target=self.object, editor=user, action='CR', log=self.log_msg) log_record.save() return HttpResponseRedirect(self.get_success_url())