On Nov 4, 11:20 am, Maksymus007 <maksymus...@gmail.com> wrote:
> I'm trying to use modelformset for my model using specified form.
> Everything works well unless i try to save forms - ale changes are
> saved, but for 22 forms django generates 91 queries (some of them are
> for auth, other parts etc - but this number should not exceed 30
> counting one query for each form). Nevertheless, i got 22 queries like
>
> SELECT (1) AS "a" FROM "finances"."gates_approvals" WHERE
> ("finances"."gates_approvals"."gate_approval_id" = 45 AND NOT
> ("finances"."gates_approvals"."gate_approval_id" = 45 ))
>
> which is totally useless. Did anyone meet such a strange behaviour?

Hello

Yes, I've seen this behaviour, all right. This looks like a
misbehaving uniqueness check and I've seen it happen in the .clean()
method of the model (in model-validation branch), and, while this is
certainly not where *you* are seeing it, the queries look just the
same.

This is the way Django handles uniqueness checks (and, quite frankly,
this is the only way to do it), however it should not be performed for
primary keys. If it wasn't a primary key field but some other
"other_unique_field" the query would look like this 'select (1) as "a"
from "table" where ("table"."other_unique_field" = 45 and not
("table"."id" = 45))', which makes perfect sense to me (this
observation was made by another django-users member, so I am not the
one to be thanked here).

Anyway, I haven't (yet) read the source of ModelFormSet, so I can't
give you any direct advice as to how to get rid of these queries.
Could you post your model declaration, by the way?

I hope my explanation helped at least a little bit.

Mark
--~--~---------~--~----~------------~-------~--~----~
You received this message because you are subscribed to the Google Groups 
"Django users" group.
To post to this group, send email to django-users@googlegroups.com
To unsubscribe from this group, send email to 
django-users+unsubscr...@googlegroups.com
For more options, visit this group at 
http://groups.google.com/group/django-users?hl=en
-~----------~----~----~----~------~----~------~--~---

Reply via email to