https://htmx.org logo
Hey! Did anyone tried to add multiple instances o...
# 🔥-django-htmx
b
Hey! Did anyone tried to add multiple instances of one Django form inside the other with HTMX? I've managed to do it visually, but I'm not sure how to process the forms (especially as it deals with files) My models:
Copy code
class Message(models.Model):
    date = models.DateField(default=timezone.now)
    message = models.TextField()

class MessagePhoto(models.Model):
    photo = models.ImageField(upload_to='memory_photos')
    message = models.ForeignKey(Memory, on_delete=models.CASCADE, related_name="message_photos")
Main form template:
Copy code
<form method="post" enctype="multipart/form-data">
        {{ message_form.as_p }}
        {% csrf_token %}
    <div id="add-photo"></div>
    <button type="submit">Submit</button>
    </form>
    <button hx-get="{% url 'fragment_add_photo' %}" hx-target="#add-photo" hx-swap="beforeend">
        Add photo
    </button>
fragment template for the photo form is just a form: