Django REST framework flat, read-write serializer

后端 未结 3 1142
一整个雨季
一整个雨季 2020-12-25 08:54

In Django REST framework, what is involved in creating a flat, read-write serializer representation? The docs refer to a \'flat representation\' (end of the section http://d

3条回答
  •  [愿得一人]
    2020-12-25 09:47

    Although this does not strictly answer the question - I think it will solve your need. The issue may be more in the split of two models to represent one entity than an issue with DRF.

    Since Django 1.5, you can make a custom user, if all you want is some method and extra fields but apart from that you are happy with the Django user, then all you need to do is:

    class MyUser(AbstractBaseUser): favourite_number = models.IntegerField()

    and in settings: AUTH_USER_MODEL = 'myapp.myuser'

    (And of course a db-migration, which could be made quite simple by using db_table option to point to your existing user table and just add the new columns there).

    After that, you have the common case which DRF excels at.

提交回复
热议问题