0

I'm using the UserProfile method in my models to extend the user.

If I want to allow the user a title ie 'Mr' and a middle initial 'A', what is the standard pratice for this?

At present in its raw format, i enter a firstname and last name and then scroll down to select the title and input any initials.

Is it possible to combine the user and userprofile fields?

TIA

Timbadu
  • 1,533
  • 1
  • 10
  • 16

1 Answers1

1

You can create a custom ModelForm with something like that:

class ProfileForm(forms.ModelForm):
    def __init__(self, *args, **kwargs):
        super(ProfileForm, self).__init__(*args, **kwargs)
        self.fields.keyOrder = ['title', 'first_name', 'middle_name', 'all other fields']

If you don't want to list all fields, you can fiddle with that keyOrder, it's just a list:

correct_order = ['title', 'first_name', 'middle_name']
other_fields = filter(lambda f: f not in correct_order, self.fields.keyOrder)
self.fields.keyOrder = correct_order + other_fields

You can also use this form in your admin.

ilvar
  • 5,718
  • 1
  • 20
  • 17