ArniReynir
ArniReynir

Reputation: 849

Adding more fields or linking user to person

Hello I'm trying to learn django and django-restful-framework.

I was wondering can I add more fields to User(contrib.auth) like so

class UserSerializer(serializers.HyperlinkedModelSerializer):

    class Meta:
        model = User
        fields = ('url', 'username', 'firstName', 'lastName', 'ssn', 'email',
                  'phone', 'jobTitle','image', 'isActive','groups')

This gives me error on firstName. I also tried to tie this with person, but no luck either

class PersonSerializer(serializers.HyperlinkedModelSerializer):
    owner = serializers.Field(source='owner.username')

    class Meta:
        model = Person
        fields = ('url', 'firstName', 'lastName', 'ssn', 'owner')



class UserSerializer(serializers.HyperlinkedModelSerializer):
    persons = serializers.ManyHyperlinkedRelatedField(view_name='person-detail')

    class Meta:
        model = User
        fields = ('url', 'username', 'persons')

I'm trying to make this so that the user can register with more information.

Upvotes: 1

Views: 75

Answers (2)

Carlton Gibson
Carlton Gibson

Reputation: 7386

I suggest you head to the Django docs on extending and/or replacing the existing user model.

Once you've got what you want as the model level see if you can serialize that to your needs. (If not post again.)

Upvotes: 3

dan-klasson
dan-klasson

Reputation: 14210

The field names are lowercase with underscores. E.g it should be first_name and not firstName.

Upvotes: 1

Related Questions