flat-painting-36912
09/22/2022, 1:13 PMflat-painting-36912
09/22/2022, 1:13 PMflat-painting-36912
09/22/2022, 3:57 PMhundreds-camera-24900
09/22/2022, 4:27 PMhundreds-camera-24900
09/22/2022, 4:28 PMflat-painting-36912
09/22/2022, 4:46 PMflat-painting-36912
09/22/2022, 4:47 PMflat-painting-36912
09/22/2022, 4:47 PMflat-painting-36912
09/22/2022, 4:50 PMflat-painting-36912
09/22/2022, 4:50 PMflat-painting-36912
09/22/2022, 4:50 PMflat-painting-36912
09/22/2022, 4:50 PMflat-painting-36912
09/22/2022, 4:52 PMpython
def hypervisors(request: HttpRequest) -> HttpResponse:
region = request.POST.get("region")
hypervisor_list = get_hypervisors(region) // API call
return render(
request,
"partials/hypervisor-select.html",
context={"hypervisors": hypervisor_list},
)
flat-painting-36912
09/22/2022, 4:52 PMhundreds-camera-24900
09/23/2022, 3:46 PMhundreds-camera-24900
09/23/2022, 3:48 PMearly-camera-41285
09/23/2022, 11:24 PMcalm-postman-56357
09/25/2022, 3:21 PM<button
hx-headers='{"X-CSRFToken": "{{ csrf_token }}"}'
hx-post="{% url "listings:listing-favorite" listing.slug %}"
>
Some text
</button>
the post view returns some json like {"added": id}
or {"removed": id}
I would like to toggle a class on the button if the response is {"added": id}
.
Is it possible to do?bitter-monkey-50309
09/25/2022, 3:45 PMcalm-postman-56357
09/25/2022, 3:47 PMcuddly-keyboard-70746
09/25/2022, 6:06 PMhundreds-camera-24900
09/26/2022, 1:18 PMhundreds-camera-24900
09/26/2022, 1:19 PMflat-painting-36912
09/28/2022, 2:23 PMflat-painting-36912
09/28/2022, 2:24 PMhtml
{% render_field form.region class+="form-control selectpicker" data-live-search="True" data-style="btn-light" hx-post="/hypervisors-v2/" hx-target='#id_hypervisors' hx-swap="innerHTML" hx-trigger="change" %}
flat-painting-36912
09/28/2022, 2:25 PMhtml
{% render_field form.hypervisors class+="form-control selectpicker" multiple=True data-live-search="True" data-style="btn-light" %}
flat-painting-36912
09/28/2022, 2:27 PMhtml
<option value="">---------</option>
{% for hypervisor in hypervisors %}
<option value="{{ hypervisor }}">{{ hypervisor }}</option>
{% endfor %}
flat-painting-36912
09/28/2022, 2:35 PMflat-painting-36912
09/28/2022, 9:08 PMflat-painting-36912
09/28/2022, 9:08 PM