https://htmx.org logo
Join Discord
Powered by
# πŸ”₯-django-htmx
  • b

    blue-gold-89534

    01/14/2022, 6:56 PM
    with a little unexpected behavior and I am thinking about filing a bug report on this - maybe someone would want to give me some feedback on that: works:
    Copy code
    html
    <table>
        <tr id="editProductRow"
            hx-target="#editProductRow"
            hx-encoding="multipart/form-data"
            hx-swap="outerHTML"
            hx-include="#editProductRow"
            hx-trigger="click target:#submitbutton">
            {% for field in form %}
                <td>{{ field }}</td>
            {% endfor %}
            <td class="text-end">
                <button type="submit"
                        class="btn btn-success"
                        id="submitbutton">
                     OK
                </button>
            </td>
        </tr>
    </table>
    does not work (but I thought it would):
    Copy code
    html
    <table>
        <tr id="editProductRow"
            hx-target="#editProductRow"
            hx-encoding="multipart/form-data"
            hx-swap="outerHTML" 
            hx-include="this" comment="<------"
            hx-trigger="click[showEditButtons()] target:#submitbutton">
            {% for field in form %}
                <td>{{ field }}</td>
            {% endfor %}
            <td class="text-end">
                <button type="submit"
                        class="btn btn-success"
                        id="submitbutton">
                     OK
                </button>
            </td>
        </tr>
    </table>
  • b

    best-garage-8297

    01/14/2022, 7:00 PM
    I have a similar code but I can't receive the fields with hx-include
  • b

    best-garage-8297

    01/14/2022, 7:01 PM
    Copy code
    html
    
    <tr data-toggle="modal" data-target="#FormSetModal"
        id="form-{{ form.prefix }}"
        hx-get="{% url 'nfe-item' %}"
        hx-target="#FormSetModal .modal-body"
        hx-inlcude="#form-{{ form.prefix }}"
        >
        <td>{{ item.product.description }}</td>
        <td>{{ item.quantity }}</td>
        <td>{{ item.value }}</td>
        {% hidden_form_fields form %}
    </tr>
  • b

    best-garage-8297

    01/14/2022, 7:06 PM
    I wonder if maybe it's the hx-trigger...
  • e

    echoing-magazine-16041

    01/14/2022, 7:12 PM
    Haven't you made a typo in here ? I read
    hx-inlcude
    instead of
    hx-include
  • b

    best-garage-8297

    01/14/2022, 7:13 PM
    OMG! πŸ˜‚ πŸ˜‚ πŸ˜‚
  • b

    best-garage-8297

    01/14/2022, 7:13 PM
    Thanks @User !
  • e

    echoing-magazine-16041

    01/14/2022, 7:13 PM
    Haha np that stuff happens πŸ˜† if you can, get your IDE to autocomplete htmx's attributes !
  • p

    prehistoric-cat-63987

    01/18/2022, 7:02 AM
    Hi please, is there a better way of doing this?
  • p

    plain-kangaroo-26043

    01/18/2022, 9:35 AM
    @User that looks more like a general Django question. I'd ask on the Django official channel. I'd give them some more context though on what you are trying to do with those querysets.
  • p

    prehistoric-cat-63987

    01/19/2022, 7:46 AM
    I understand it's general Django question, and I'm using htmx to update the ratings. So I'm sorry for asking here. But what I'm trying to do is query the database to update the numbers of 5, 4, 3, 2 and 1 star ratings in the db after another review has been submitted
  • f

    fresh-controller-36545

    01/19/2022, 8:22 AM
    I agree this is better suited for the Django Discord; totally unrelated to htmx. But you can get started here: https://docs.djangoproject.com/en/dev/ref/models/expressions/
  • c

    calm-motorcycle-68687

    01/19/2022, 12:32 PM
    The django/htmx way would be to have a view that renders a form. If you want a quick solution a modelform on the review model would be a good option. You add the htmx attributes to the template in the form so that the form is submitted to the form view. If everything is validated OK a new row should be added in the db. I use the pattern that I have a "page" view that renders the whole site page. In that template I have markup for lazy loading the form from the "form view". https://htmx.org/examples/lazy-load/ My urls would look like www.example.com/mypage and www.example.com/mypage/~form
  • p

    prehistoric-cat-63987

    01/19/2022, 12:39 PM
    Ok, thank you.
  • s

    salmon-xylophone-28580

    01/20/2022, 11:01 AM
    Has anybody solved this django challenge with htmx? Related question: https://stackoverflow.com/questions/52699303/django-admin-list-filter-getting-too-long
  • b

    blue-gold-89534

    01/20/2022, 12:02 PM
    lol i was wondering the same thing couple of days ago
  • b

    bland-coat-6833

    01/20/2022, 12:18 PM
    How much JS is in the admin these days? htmx sprinkles could be a nice thing to have examples of.
  • b

    bland-coat-6833

    01/20/2022, 12:22 PM
    HA! https://code.djangoproject.com/wiki/NewformsHOWTO Can't believe that wiki page is still there.
    s
    • 2
    • 6
  • b

    blue-gold-89534

    01/20/2022, 12:35 PM
    #oldschool
  • s

    salmon-xylophone-28580

    01/20/2022, 1:36 PM
    NewFormsHOWTO deleted
  • a

    acoustic-lawyer-26558

    01/20/2022, 2:09 PM
    how would i trigger an event with focusout on a text input?
  • f

    fresh-controller-36545

    01/20/2022, 2:49 PM
    Looks like a subclassed filter with Select2 (bundled into Django admin by default) could already go a long way here. How would you imagine htmx's use case here? Can't think of a way it could be beneficial, as it's mostly about changing the
    input
    / way the filter is parametrized.
  • f

    fresh-controller-36545

    01/20/2022, 2:54 PM
    You can even get the Select2-AJAX API for free, when defining using
    search_fields
    in the correlating model admin.
  • s

    salmon-xylophone-28580

    01/20/2022, 3:04 PM
    Thank you for the hint to the "free" ajax-api.
  • f

    fancy-twilight-24901

    01/20/2022, 7:33 PM
    There is a related PR to Django. https://github.com/django/django/pull/15331
  • f

    fancy-twilight-24901

    01/20/2022, 7:33 PM
    Fixed #27471 -- Make admin's list_filter choices collapsable
  • c

    calm-motorcycle-68687

    01/20/2022, 8:39 PM
    https://hakibenita.com/how-to-add-a-text-filter-to-django-admin Here is a way to do text filter I have used. I bet you could do some htmx with this setup.
  • b

    bitter-family-65697

    01/21/2022, 8:53 AM
    Hi all. Can someone help me and give me a hint? I am trying to catch the request sent from htmx in the class based view, but in this way:
    Copy code
    def dispatch(self, request, *args, **kwargs):
            if 'click' in request.POST:
                return render(request, self.some_template_name,)
    I want to catch different queries in one view. Is it at all possible or do I have to write a separate view for it? Thx for help and have a nice day πŸ™‚
  • p

    plain-kangaroo-26043

    01/21/2022, 9:24 AM
    You can check various HTTP headers: https://htmx.org/reference/#request_headers
  • b

    bland-coat-6833

    01/21/2022, 9:39 AM
    You can also use the Django middleware: https://github.com/adamchainz/django-htmx Then you get an
    htmx
    property on the request that you can check.
1...414243...100Latest