money-manager/expenses/views.py

18 lines
548 B
Python
Raw Normal View History

2023-09-17 16:54:34 +08:00
from django.shortcuts import render
from django.http import HttpResponseRedirect
from django.urls import reverse
from django.contrib import messages
from .models import Expense
def restore_item(request, item_id):
try:
item = Expense.objects.get(pk=item_id)
item.deleted = False
item.save()
messages.success(request, "Item restored successfully.")
except Expense.DoesNotExist:
messages.error(request, "Item not found.")
return HttpResponseRedirect(reverse("admin:expenses_expense_changelist"))