¿Cómo aumentar el rendimiento de los formularios?

Tengo forma:

class AdmItemForm(forms.ModelForm):
    id = forms.ModelChoiceField(queryset=Article.objects.all(), widget=forms.HiddenInput())
    mainimage = forms.ImageField(widget=AdmImageWidget(), required=False)
    tags = TagField(required=False)
    .....

class Meta:
    model = Article
    fields = ('id', 'category', 'date', ....)

but... In the articles table is 10 000 records... Form isn't opened, browser loads data forever.

What happens? Is the ModelChoiceField retrieves all data from a table?

¿Como arreglarlo?

preguntado el 27 de agosto de 11 a las 23:08

1 Respuestas

If you've got 10,000 records belonging to your Article model, then the queryset you're passing to ModelChoiceField will mean that it contains 10,000 items.

The simple solution is to restrict that queryset to contain only what you actually need: does the form need to contain every single article?

Long story short, see if you can restrict the query in any way, i.e.:

id = forms.ModelChoiceField(queryset=Article.objects.\
    filter(published=True))

Respondido 28 ago 11, 04:08

No es la respuesta que estás buscando? Examinar otras preguntas etiquetadas or haz tu propia pregunta.