Skip to content

Commit

Permalink
fix form prefixes in list view
Browse files Browse the repository at this point in the history
  • Loading branch information
hmpf committed Jan 24, 2025
1 parent 131589c commit e85bc83
Showing 1 changed file with 7 additions and 4 deletions.
11 changes: 7 additions & 4 deletions src/argus/htmx/timeslot/views.py
Original file line number Diff line number Diff line change
Expand Up @@ -34,11 +34,14 @@ class TimeslotMixin:
model = Timeslot
prefix = "timeslot"

def get_prefix(self):
if self.object and self.object.pk:
return self.prefix + f"-{self.object.pk}"
def _get_prefix(self, pk):
if pk:
return self.prefix + f"-{pk}"
return self.prefix

def get_prefix(self):
return self._get_prefix(getattr(self.object, "pk", None))

def get_queryset(self):
qs = super().get_queryset().prefetch_related("time_recurrences")
return qs.filter(user_id=self.request.user.id)
Expand Down Expand Up @@ -90,7 +93,7 @@ def get_context_data(self, **kwargs):
context = super().get_context_data(**kwargs)
forms = []
for obj in self.get_queryset():
form = TimeslotForm(None, instance=obj)
form = TimeslotForm(None, instance=obj, prefix=self._get_prefix(obj.pk))
formset = make_timerecurrence_formset(timeslot=obj)
forms.append({"form": form, "formset": formset})
context["form_list"] = forms
Expand Down

0 comments on commit e85bc83

Please sign in to comment.