Fwd: Why django (when using inlineformset) run 20 times the same SQL for each record (form)?

85 views
Skip to first unread message

Fellipe Henrique

unread,
Oct 15, 2015, 4:43:29 PM10/15/15
to Django Users
Hello,

I try to use "inlineformset", but for each record (each form)  django create and run 20 selects (same select), I take the one snapshot [1].

Can anyone explain to me, why django do that? How can I fix these? It's take a some amout of time!!! 

Here is my view:

ofertasinlineformset = inlineformset_factory(Assinatura, Ofertas,
form=OfertasEditForm,
max_num=ass_ativa.total_produtos_oferta,
extra=ass_ativa.total_produtos_oferta,
exclude=(),
can_delete=False)
form: 
class OfertasEditForm(ModelForm):
class Meta:
model = Ofertas
exclude = []

def __init__(self, *args, **kwargs):
u = kwargs.pop('usuario', None)
super(OfertasEditForm, self).__init__(*args, **kwargs)
self.fields['produto'].queryset = Produto.objects.filter(usuario_id=u).filter(status='A')


Debug [1]:

Inline image 1


T.·.F.·.A.·.     S+F
Fellipe Henrique P. Soares

e-mail: > echo "lkrrovknFmsgor4ius" | perl -pe \ 's/(.)/chr(ord($1)-2*3)/ge'
Twitter: @fh_bash

Mark Steadman

unread,
Oct 19, 2015, 6:18:55 PM10/19/15
to Django users
Can you provide the HTML you're using to render the formset view?

Fellipe Henrique

unread,
Oct 19, 2015, 7:30:19 PM10/19/15
to Django Users
It's a simple HTML with these code:

<div class="col-md4">
{{ formset helper }}
</div>

T.·.F.·.A.·.     S+F
Fellipe Henrique P. Soares

e-mail: > echo "lkrrovknFmsgor4ius" | perl -pe \ 's/(.)/chr(ord($1)-2*3)/ge'
Twitter: @fh_bash

--
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/d4ff4f3d-6c8c-4bda-bd4a-971639febe71%40googlegroups.com.
For more options, visit https://groups.google.com/d/optout.

Mark Steadman

unread,
Oct 20, 2015, 8:56:56 AM10/20/15
to Django users
Are you sure that's the code? I think that would generate an error as you can't combine variables in the same {{ ... }} tag.

Not being pedantic; it's just important to make sure we're looking at the right HTML to help diagnose the problem. Can you paste the whole view?

Thanks!

Fellipe Henrique

unread,
Oct 20, 2015, 9:26:44 AM10/20/15
to Django Users
Here is my view, model and form:  https://gist.github.com/fellipeh/f10824e61552efd71c8e

Here is my HTML:

<form action="{% url 'desk_ofertas' %}" method="post" id="form_ofertas">
{% csrf_token %}
{{ formset.management_form }}
<div class="form-group">
<div class="table-responsive">
{% crispy formset helper %}
</div>
</div>

Regards,

T.·.F.·.A.·.     S+F
Fellipe Henrique P. Soares

e-mail: > echo "lkrrovknFmsgor4ius" | perl -pe \ 's/(.)/chr(ord($1)-2*3)/ge'
Twitter: @fh_bash

Steadman

unread,
Oct 21, 2015, 3:13:47 PM10/21/15
to django...@googlegroups.com, Fellipe Henrique
I don’t have any experience with Crispy Forms, but I wonder if you get the same number of queries when you just print out the form and helper?
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/ya5E5UQtEQU/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.
Reply all
Reply to author
Forward
0 new messages