def save_commercial(self, data): try: commercial = Commercial() commercial.name = data.get('name') commercial.brand = Brand.objects.get(pk=data.get('brand')) commercial.save() 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([commercial.id], CleanCache.MODE_INSERT) return commercial, self.SAVE_SUCCESSFUL except Exception, e: return None, self.SAVE_ERROR
def insert_commercial(self): if not Commercial.objects.filter(name='Comercial de prueba').exists(): entry = Entry() entry.name = 'Rubro de prueba' entry.save() brand = Brand() brand.entry = entry brand.name = 'Marca de prueba' brand.save() commercial = Commercial() commercial.brand = brand commercial.name = 'Comercial de prueba' commercial.save()