Basic table inline edit functionality
This commit is contained in:
@ -1,3 +1,8 @@
|
||||
from typing import Any
|
||||
|
||||
from django.http import Http404
|
||||
|
||||
from project.main.models import Person
|
||||
from project.main.views.demo_view_base import DemoViewBase
|
||||
|
||||
|
||||
@ -5,3 +10,37 @@ class TableInlineEditView(DemoViewBase):
|
||||
template_name = "main/table_inline_edit.html"
|
||||
active_section = "table-inline-edit"
|
||||
title = "Table Inline Edit"
|
||||
|
||||
def get_context_data(self, **kwargs) -> dict[str, Any]:
|
||||
context_data = super().get_context_data(**kwargs)
|
||||
|
||||
persons = Person.objects.all()
|
||||
|
||||
context_data.update(
|
||||
{
|
||||
"persons": persons,
|
||||
}
|
||||
)
|
||||
return context_data
|
||||
|
||||
|
||||
class TableInlineEditRowView(DemoViewBase):
|
||||
template_name = "main/table_inline_table_row.html"
|
||||
|
||||
def get_context_data(self, **kwargs) -> dict[str, Any]:
|
||||
context_data = super().get_context_data(**kwargs)
|
||||
|
||||
try:
|
||||
person = Person.objects.get(pk=kwargs.get("pk"))
|
||||
except Person.DoesNotExist:
|
||||
raise Http404("Person not found")
|
||||
|
||||
action = self.request.GET.get("action")
|
||||
|
||||
context_data.update(
|
||||
{
|
||||
"person": person,
|
||||
"is_editing": action != "cancel",
|
||||
}
|
||||
)
|
||||
return context_data
|
||||
|
||||
Reference in New Issue
Block a user