示例#1
0
 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()
示例#2
0
 def form_valid(self, form):
     self.object = form.save(commit=False)
     dataPost = self.request.POST
     self.object.save()
     for data in dataPost:
         if 'realized' in data:
             try:
                 realized = datetime.datetime.strptime(dataPost.get(data), '%d/%m/%Y').strftime('%Y-%m-%d')
                 detail = CommercialDateDetail()
                 detail.date = realized
                 self.object.commercial_date_detail_set.add(detail)
             except:
                 pass
     if settings.APPLICATION_CACHE:
         clean_cache = CleanCache()
         clean_cache.set_cache_result_tag(Commercial.get_commercial_tag())
         clean_cache.set_model(Commercial)
         clean_cache.update_cache_by_id([self.object.id], CleanCache.MODE_INSERT)
     return super(CommercialCreateView, self).form_valid(form)