31👍
✅
You need to assign the value being returned from the save()
method:
obj = empresa.save()
print(obj.id)
The reason is that save()
calls create()
of the Serializer which returns an object instance
4👍
Hi you need do like this
empresa = EmpresaCreateSerializer(data=data)
empresa.user = user_id
if(empresa.is_valid()):
empresa.save() //Here you need use these two methods **create,perform_create**
print(empresa.data['id'])
- Python/Tornado – compressing static files
- Django Comments: Want to remove user URL, not expand the model. How to?
- How to modify jQuery mobile history Back Button behavior
- TemplateSyntaxError: 'with' expected with atleast one variable assignment
Source:stackexchange.com