python - Django Rest Framework not returning all fields after creation -


Summary: I am using Django Rest Framework to create a simple object (shown below) in the serial, I am only taking the required field, however, I am not getting all the fields back in POST answer (like ID, Construction_date etc.). I'm only getting the fields for non-reading. Please help:

model

  class document (models.Model): owner = model.teaserfilled (zero) = false) Description = Modlkkarfild (max_length = 512, blank = true) made = time = Modlkdetafailfild (auto_now_add = true) update_time = Modlkdetafailfild (auto_now = true) expiry_time = Modlkdetaimfild (blank = true, blank = True) Position = Model. Terfield (max_length = 128, empty = true) Size = models.IntegerField (empty = True) type = models.I ntegerField (max_length = 128, null = true)  

Siriylijhr

  class DocumentCreateSerializer (Read_only_fields = ( 'id', 'owner', 'created_time', '', '', 'Update_time')  

See

  class DocumentViewSet (viewsets.ModelViewSet): ... ... def get_serializer_class ) If self.request. method == 'POST': serializer_c Lass = DocumentCreateSerializer elif self.request.method == 'GET': serializer_class = DocumentGetSerializer elif self.request.method == 'PUT': serializer_class = DocumentUpdateSerializer elif self .request.method == 'patch': serializer_class = DocumentUpdateSerializer returns serializer_class  

If you If you want to return those fields, then you THEY field :

  class DocumentCreateSerializer (serializers.ModelSerializer): class Meta: model = document field = ( 'id', 'owner', 'Bnaia_taim' Adytn_taim ',' Read_only_fields = ( 'id', 'owner', 'time', 'Adytn_taim')  
Akspreshn_taim ',' Description ',' size 'made,' type ',' Position '

Comments

Popular posts from this blog

apache - 504 Gateway Time-out The server didn't respond in time. How to fix it? -

c# - .net WebSocket: CloseOutputAsync vs CloseAsync -

c++ - How to properly scale qgroupbox title with stylesheet for high resolution display? -