2

I'm trying to create two different types of users in Django using AbstractUser. I've created two models that inherit from my AbstractUser model.

How do I update the UserCreationForm so that it has a field for user type?

Bcomposer
  • 47
  • 6

1 Answers1

3

Just override the built-in UserCreationForm and adjust the fields as necessary.

class CustomUserCreationForm(UserCreationForm):
    class Meta:
        model = CustomUser
        fields = UserCreationForm.Meta.fields + ('type',)
Harben
  • 1,802
  • 1
  • 11
  • 16
  • Thank you! This helps a lot. By 'type', is this where I would include the names of my models that inherit from AbstractUser? – Bcomposer Aug 06 '20 at 19:52
  • Yeah you'd just be appending another field_name to the tuple of fields in the UserCreationForm: `fields = UserCreationForm.Meta.fields + ('user_type',)`. – Harben Aug 06 '20 at 19:55
  • No worries! If you could mark as answer, that would be awesome! – Harben Aug 07 '20 at 15:23
  • new to stackoverflow! I missed that the first time. just marked it. – Bcomposer Aug 08 '20 at 07:13