views:

106

answers:

1

Hi guys, i have a form, but i need to re-orden the form fields, plese some body will tell me how? im try with fields = ['x','y'] but nothing happen.

class DiligenciaForm(ModelForm):
    titulo = forms.CharField(max_length=70,help_text='Dele un nombre a su diligencia.')
    tipo = forms.ChoiceField(choices=TIPO)  
    vias= forms.TypedChoiceField(widget=forms.RadioSelect(), choices=CHOICES)    



class Meta:
    model = Diligencia
    exclude =('socio','secuencia','ffin','fecha','fentrada','status')
    fields = ['titulo', 'tipo','vias']

i need this orden "titulo", "tipo" and "vias"... but is not working

Thanks

+1  A: 

I'll assume you meant you need to reorder the forms? The only problem I see with your code is that you have both the exclude and the fields settings in the Meta class. Also (although it might not be this way in your code) the indentation is wrong. So, fixed, it would look something like this:

class DiligenciaForm(ModelForm):
    titulo = forms.CharField(max_length=70, help_text='Dele un nombre a su diligencia.')
    tipo = forms.ChoiceField(choices=TIPO)  
    vias= forms.TypedChoiceField(widget=forms.RadioSelect(), choices=CHOICES)    

    class Meta:
        model = Diligencia
        fields = ['titulo', 'tipo', 'vias',]

Now if you need to reorder the fields just change their order in the 'fields' variable to whatever you want. Also make sure you're running Django version 1.1 as the documentation seems to indicate the ability to reorder the fields was introduced in that version (see here: http://docs.djangoproject.com/en/dev/topics/forms/modelforms/#using-a-subset-of-fields-on-the-form )

John Debs
Thanks , is working, i upgraded to django 1.1 :)
Asinox