K
K
khmlnk2015-07-12 21:55:27
Django
khmlnk, 2015-07-12 21:55:27

How to make an extended user model?

Good day, gentlemen. Can you please tell me how to register users using the Django rest framework, but with an extended model?
Here, for example, I have a UserProfile model that has a field

class UserProfile(models.Model):
    user = models.OneToOneField(User, related_name='profile')
    city = models.CharField(max_length=255)

When registering users, in addition to the standard username / email fields, the city field must also be filled in, and this field must immediately be "attached" to the user.
Something I can not understand in any way how to serialize two models at a time.

Answer the question

In order to leave comments, you need to log in

1 answer(s)
M
marazmiki, 2015-07-13
@marazmiki

It is very convenient to change the logic of creating and editing objects through serializers . But in general, it seems to me that a more correct way is to transfer the city field to the user model, since 3 major versions of jang can do this out of the box .

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question