Either use a model serializer or define the fields on which derialization is to be applied when the json data you post is converted into the python dictionary format. A model serializer if used would pick up the fields from the model otherwise if you wish to have different fields then you must explicitly mention them which you commented in your code
in your case On Tuesday, June 27, 2017 at 11:23:02 PM UTC+5:30, Huy Hớn wrote: > > Hi all, > I'm following guide to define serializers > http://www.django-rest-framework.org/tutorial/1-serialization/ > I would like to modified data before saving to database, but when I check > in function create() validated_data value it's returns null object. > I'm using http post. > Could you guys please help me? > > > > *Views.py* > > > > <https://lh3.googleusercontent.com/-i8nwkZ-bMOg/WVKaHwWM1WI/AAAAAAAACwA/s1Mv69ZMFyo5Cw-cCaPT84n6KdA15myOACEwYBhgL/s1600/code%2Bviews.JPG> > > *Serializers.py* > <https://lh3.googleusercontent.com/-i8nwkZ-bMOg/WVKaHwWM1WI/AAAAAAAACwA/s1Mv69ZMFyo5Cw-cCaPT84n6KdA15myOACEwYBhgL/s1600/code%2Bviews.JPG> > > > <https://lh3.googleusercontent.com/-XXiu0q2ZyS4/WVKao9Mg46I/AAAAAAAACwI/eoc4DG3cyPAxp5hWSQyesgyrYuUzy390QCLcBGAs/s1600/serializers.JPG> > *Console used to check validated_data value, it's returns null object* > <https://lh3.googleusercontent.com/-i8nwkZ-bMOg/WVKaHwWM1WI/AAAAAAAACwA/s1Mv69ZMFyo5Cw-cCaPT84n6KdA15myOACEwYBhgL/s1600/code%2Bviews.JPG> > > > > > <https://lh3.googleusercontent.com/-YDejiw8DhtA/WVKbHl5pjjI/AAAAAAAACwM/fNHkRkPcNScF9pZs8lsRxIjvrmXmRI__QCLcBGAs/s1600/console.JPG> > Thanks, > <https://lh3.googleusercontent.com/-i8nwkZ-bMOg/WVKaHwWM1WI/AAAAAAAACwA/s1Mv69ZMFyo5Cw-cCaPT84n6KdA15myOACEwYBhgL/s1600/code%2Bviews.JPG> > > Hon Trang > > <https://lh3.googleusercontent.com/-i8nwkZ-bMOg/WVKaHwWM1WI/AAAAAAAACwA/s1Mv69ZMFyo5Cw-cCaPT84n6KdA15myOACEwYBhgL/s1600/code%2Bviews.JPG> > -- You received this message because you are subscribed to the Google Groups "Django REST framework" group. To unsubscribe from this group and stop receiving emails from it, send an email to [email protected]. For more options, visit https://groups.google.com/d/optout.
