Django Dynamic Formsets

466 views
Skip to first unread message

Leandro Alves

unread,
Apr 7, 2014, 5:13:19 PM4/7/14
to django...@googlegroups.com
Hi, 

I wonder if anyone knows of any example of django-dynamic-formsets [1] that works with Django 1.6?

So far all I found on the internet are over 3 years old and they don't work with Django version 1.6. 

I am willing to pay for any example that works if necessary. :)

Thanks in advance, 

Leandro


Gladson Simplício Brito

unread,
Apr 7, 2014, 5:33:48 PM4/7/14
to django...@googlegroups.com
The project was migrated to another repository:



--
You received this message because you are subscribed to the Google Groups "Django users" group.
To unsubscribe from this group and stop receiving emails from it, send an email to django-users...@googlegroups.com.
To post to this group, send email to django...@googlegroups.com.
Visit this group at http://groups.google.com/group/django-users.
To view this discussion on the web visit https://groups.google.com/d/msgid/django-users/95dc89cb-cdd7-43c5-adca-da0a1aaf9573%40googlegroups.com.
For more options, visit https://groups.google.com/d/optout.

Leandro Alves

unread,
Apr 7, 2014, 6:16:05 PM4/7/14
to django...@googlegroups.com
Yes.. I have tried that one as well.. but the example still doesn't work... =/

Any freelance available for this? 

Thanks for the feedback!

Leandro


--
You received this message because you are subscribed to a topic in the Google Groups "Django users" group.
To unsubscribe from this topic, visit https://groups.google.com/d/topic/django-users/_sfhHrcDJBs/unsubscribe.
To unsubscribe from this group and all its topics, send an email to django-users...@googlegroups.com.

To post to this group, send email to django...@googlegroups.com.
Visit this group at http://groups.google.com/group/django-users.

Gladson Simplício Brito

unread,
Apr 7, 2014, 6:43:06 PM4/7/14
to django...@googlegroups.com

Leandro Alves

unread,
Apr 7, 2014, 7:24:35 PM4/7/14
to django...@googlegroups.com
Brother, I think I have tried all of those already and some other around the internet... 
I couldn't find anyone that works with Django 1.6. 

I will send you an email with what I need, ok? :)

Thanks again!

Leandro

Gladson Simplício Brito

unread,
Apr 7, 2014, 7:42:53 PM4/7/14
to django...@googlegroups.com

Leandro Alves

unread,
Apr 7, 2014, 7:53:13 PM4/7/14
to django...@googlegroups.com
Done. :)

Thanks!!!

Venkatraman S

unread,
Apr 8, 2014, 12:48:15 AM4/8/14
to django...@googlegroups.com
Have you tried the jquery formset - works like a breeze for me. 


--

Alejandro Perez

unread,
Apr 8, 2014, 1:32:44 PM4/8/14
to django...@googlegroups.com
Hey Leandro, I'm looking for something like that and your topic question is rolling in my head.. Could you please share your solution with the community? :D
Thanks !!! :)

Leandro Alves

unread,
Apr 8, 2014, 4:43:05 PM4/8/14
to django...@googlegroups.com
Hello Alejandro!!!

Man...I swear, if I had it I would be sooo happy to share... :)

I still couldn't get a normal Formset example to work.. Do you have any simple foo example to share? hehehe

I also tried to make the "demo" example from django-dynamic-formsets works with Django 1.6. But not luck...

But I keep trying and I will post here If I got any news. :)

Best regards, 

Leandro

Leandro Alves

unread,
Apr 8, 2014, 4:46:55 PM4/8/14
to django...@googlegroups.com
Hello Venkatraman,

Yes.. I saw this one was well... and I want to try it.. but I'm still learning about Formsets...
Would you have any basic simple foo example to share? :)

Best, 

Leandro

Venkatraman S

unread,
Apr 9, 2014, 5:19:11 AM4/9/14
to django...@googlegroups.com
Actually, there is nothing more to it. Include the js and create the formset_factory and start using it in the template by iterating over it. In the view, post-POST, again iterate over the formsets. Bulk of the work is done by the js and you dont have to do much in django. There is a minor bug in the js which lets even one row in the UI to get deleted, but its not a show-stopper :)

Let me know if its still trouble and I shall write something up.

Leandro Alves

unread,
Apr 9, 2014, 11:28:48 AM4/9/14
to django...@googlegroups.com
Hi again, 

So I followed the documentation and created a formset as we have there. 
https://docs.djangoproject.com/en/1.6/topics/forms/formsets/

Then I followed the documentation and included the django-formset-js:

But I can't get the buttons "Add another" neither "Delete" working.  
And I'm sure I'm missing something that I don't know yet.  

This is what I have so far: 


forms.py

from django import forms
from django.forms.formsets import formset_factory

class ArticleForm(forms.Form):
    title = forms.CharField()
    pub_date = forms.DateField()


views.py

from django.forms.formsets import formset_factory
from django.shortcuts import render_to_response
from formsets.djdocs.forms import ArticleForm

def manage_articles(request):
    ArticleFormSet = formset_factory(ArticleForm, can_delete=True, extra=2)
    if request.method == 'POST':
        formset = ArticleFormSet(request.POST, request.FILES)
        if formset.is_valid():
            # do something with the formset.cleaned_data
            for form in formset:
                print(form.as_table())
            pass
    else:
        formset = ArticleFormSet()
        
    return render_to_response('djdocs/manage_articles.html', {'formset': formset})


urls.py

from django.conf.urls import patterns, include, url
from formsets.djdocs.views import manage_articles

urlpatterns = patterns('djdocs.views',
    url(r'^$', manage_articles),
)


template manage_articles.html

{% extends "index.html" %}
{% block content %}

{% load formset_tags %}
<div id="formset" data-formset-prefix="{{ formset.prefix }}">
    {{ formset.management_form }}

    <div data-formset-body>
        <!-- New forms will be inserted in here -->
        {% for form in formset %}
            <div data-formset-form>
                {{ form }}
<div class="hidden">{{ form.DELETE }}</div>
                <button type="button" data-formset-delete-button>Delete form</button>
            </div>
        {% endfor %}
    </div>

    <!-- The empty form template. By wrapping this in a <script> tag, the
    __prefix__ placeholder can easily be replaced in both attributes and
    any scripts -->
    <script type="form-template" data-formset-empty-form>
        {% escapescript %}
            <div data-formset-form>
                {{ formset.empty_form }}
                <button type="button" data-formset-delete-button>Delete form</button>
            </div>
        {% endescapescript %}
    </script>

    <!-- This button will add a new form when clicked -->
    <input type="button" value="Add another" data-formset-add>

    <script>jQuery(function($) {
        $("#formset").formset({
            animateForms: true
        });
    });</script>

</div>

{% endblock %}

In the index.html file I'm loading the .js like:

{% load staticfiles %}
<script src="{% static "js/jquery.js" %}"></script>
<script src="{% static "js/jquery.formset.js" %}"></script>


Any advice? :)

Best regards, 

Leandro

Venkatraman S

unread,
Apr 12, 2014, 4:38:05 PM4/12/14
to django...@googlegroups.com
Can you try with this : https://gist.github.com/venkasub/10544716
It works for me. Let me know if you have trouble.

-V


Reply all
Reply to author
Forward
0 new messages