def save_commercial_dates(self, project): commercial = project.commercial new = CommercialDateDetail.objects.filter(commercial=commercial).exists() if new: CommercialDateDetail.objects.filter(commercial=commercial).delete() if self.data_commercial.get('dates') is not None: for _commercial in self.data_commercial.get('dates'): if _commercial.get('date') != '' and _commercial.get('date') != None: commercial_detail = CommercialDateDetail() commercial_detail.commercial = commercial commercial_detail.date = self.format_date(_commercial.get('date')) commercial_detail.save()