简体   繁体   中英

DRF other fields in serializer on get and on post

I'm trying for a few hour how to get other fields representation in serializer when i'm doing get and other when i'm doing post. 在此处输入图像描述

I want this all data which are in author field in json, but lower in html form i want only choose exist user from list. When i change author field to display only url then i can choose author from list. 在此处输入图像描述

Is it possible to get author info like on first screen and have only possibility to choose author from user list without editing all user fields?

I think what you need is author as a ForeignKey in You Model.

Something like:

author = models.ForeignKey(
    Author,
    on_delete=models.CASCADE
)

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM