def view(request, id, slug=None): template_data = {} ingredient = cache.get(cache_mapper.get_ingredient_key(int(id))) if not ingredient: ingredient = get_object_or_404(Ingredient, pk=id) cache.set(cache_mapper.get_ingredient_key(ingredient), ingredient) template_data['ingredient'] = ingredient template_data['form'] = UnitChooserForm(data={'ingredient_id': ingredient.id, 'amount': 100, 'unit': None}) return render(request, 'ingredient/view.html', template_data)
def view(request, id, slug=None): template_data = {} ingredient = cache.get(cache_mapper.get_ingredient_key(int(id))) if not ingredient: ingredient = get_object_or_404(Ingredient, pk=id) cache.set(cache_mapper.get_ingredient_key(ingredient), ingredient) template_data['ingredient'] = ingredient template_data['form'] = UnitChooserForm(data={'ingredient_id': ingredient.id, 'amount': 100, 'unit': None}) template_data['show_shariff'] = True return render(request, 'ingredient/view.html', template_data)
def save(self, *args, **kwargs): ''' Reset the cache ''' super(Ingredient, self).save(*args, **kwargs) cache.delete(cache_mapper.get_ingredient_key(self.id))