field impossible to update

18 views
Skip to first unread message

andrea boetto

unread,
Jul 3, 2015, 11:21:35 AM7/3/15
to django-res...@googlegroups.com
I have to create inside my model a field that can must be set on creation but can not be updated.
the only solution that I have found (and I'm able to make it work) is to create two different serializer  one for create and on for update operation, since I have only this difference does it exists a more clean and compact solution?


andrea boetto

unread,
Jul 3, 2015, 12:47:25 PM7/3/15
to django-res...@googlegroups.com


Il giorno venerdì 3 luglio 2015 17:21:35 UTC+2, andrea boetto ha scritto:
I have to create inside my model a field that can must be set on creation but can not be updated.
the only solution that I have found (and I'm able to make it work) is to create two different serializer  one for create and on for update operation, since I have only this difference does it exists a more clean and compact solution?

I have to replicate this behaviour on multiple serializers/model so this is why I'm asking
should I create a custom field? 

Aron Podrigal

unread,
Jul 4, 2015, 11:11:04 PM7/4/15
to django-res...@googlegroups.com
Use the Model.clean method and check if pk is None. And for the rest serializer overide init and add/remove that particular field dynamically.
Reply all
Reply to author
Forward
0 new messages