Hello! I use model formset with queryset parameter and found some strange django behaviour:
In my model formset forms 'id' fields are always replaced by ModelChoiceField instances. That become to be a problem when formset.is_valid() and formset.save() methods are called - every such call generates select-sql query to obtain single database record to with model instance. Because my model has 3 millions records and many users, it can significally decrease performance. I've make quick hack solution, but it seems like stub. ------------------------------------------------------------------- class HackedIdModelFormSet(BaseModelFormSet): def __init__(self, *args, **kwargs): super(HackedIdModelFormSet, self).__init__(*args, **kwargs) for form in self.forms: form.fields['id'] = forms.IntegerField( initial=form.fields['id'].initial, required=False, widget=forms.HiddenInput(), ) AssignmentStudentFormset = modelformset_factory(... formset=HackedModelFormSet,...) ---------------------------------------------------- Want to ask is this django behaviour is bug or feature? Is there a good way to avoid autocreating ModelChoiceField for my id fields? Thanks! additional info: - my django VERSION = (1, 2, 0, 'alpha', 1), python 2.6 - formset form fields are replaced in BaseModelFormSet.add_fields() method - select sql requests to every form record are generated in ModelChoiceField.to_python() method - of course, I'm not going to change id values. -- You received this message because you are subscribed to the Google Groups "Django users" group. To post to this group, send email to django-us...@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.