https://htmx.org logo
i ended up using your method, as it's very challen...
# 🔥-django-htmx
r
i ended up using your method, as it's very challenging to modify existing Django CBVs to make them do exactly what I want. The (simplified) code looks like this:
Copy code
python
class RefreshTableMixin:
    """Fire an HX-Trigger event to be handled client side, to indicate that a table need to be refreshed.
    """

    def build_response(self, request, *args, **kwargs):
        response = super().build_response(self, request, *args, **kwargs)
        trigger_client_event(response, name=REFRESH_TABLE_EVENT, params=None)
        return response


class EmptyResponse:
    def build_response(self, request, *args, **kwargs):
        return HttpResponse("")


class HTMXDeleteView(RefreshTableMixin, EmptyResponse, DeleteView):
    """Delete View with empty response and no redirection
    Add a custom event to be used client-side with HTMX.
    """

    def delete(self, request, *args, **kwargs):
        self.object = self.get_object()
        self.object.delete()
        response = self.build_response(request)

        return response