How to get data from multiple nested serializer? The 2019 Stack Overflow Developer Survey Results Are In Unicorn Meta Zoo #1: Why another podcast? Announcing the arrival of Valued Associate #679: Cesar Manara The Ask Question Wizard is Live! Data science time! April 2019 and salary with experienceGson: How to exclude specific fields from Serialization without annotationshaystack isn't indexing my multivalueWhat is wrong with my models.py?Permission checks in DRF viewsets are not working rightSerializing custom related field in DRFDjango-Rest-Framework - How to serialize queryset from an unrelated model as nested serializerCustomer User Authentication error : AttributeError: Manager isn't available; 'auth.User' has been swapped for 'user_management.CustomUser'Get nested serialized data as oneGot “ValueError: invalid literal for int() with base 10: 'Trancel'” when using two paramenters in detailview in DjangoHow to implement update_or_create inside create method of ModelSerializer

Intergalactic human space ship encounters another ship, character gets shunted off beyond known universe, reality starts collapsing

How do you keep chess fun when your opponent constantly beats you?

Does Parliament hold absolute power in the UK?

Am I ethically obligated to go into work on an off day if the reason is sudden?

Can each chord in a progression create its own key?

What to do when moving next to a bird sanctuary with a loosely-domesticated cat?

"... to apply for a visa" or "... and applied for a visa"?

Are there continuous functions who are the same in an interval but differ in at least one other point?

Is there a way to generate uniformly distributed points on a sphere from a fixed amount of random real numbers per point?

Do warforged have souls?

What happens to a Warlock's expended Spell Slots when they gain a Level?

Why can't devices on different VLANs, but on the same subnet, communicate?

What is the padding with red substance inside of steak packaging?

Did the UK government pay "millions and millions of dollars" to try to snag Julian Assange?

Why did Peik Lin say, "I'm not an animal"?

How do spell lists change if the party levels up without taking a long rest?

Is an up-to-date browser secure on an out-of-date OS?

My body leaves; my core can stay

Working through the single responsibility principle (SRP) in Python when calls are expensive

Why don't hard Brexiteers insist on a hard border to prevent illegal immigration after Brexit?

Make it rain characters

Is it ok to offer lower paid work as a trial period before negotiating for a full-time job?

How to handle characters who are more educated than the author?

Does Parliament need to approve the new Brexit delay to 31 October 2019?



How to get data from multiple nested serializer?



The 2019 Stack Overflow Developer Survey Results Are In
Unicorn Meta Zoo #1: Why another podcast?
Announcing the arrival of Valued Associate #679: Cesar Manara
The Ask Question Wizard is Live!
Data science time! April 2019 and salary with experienceGson: How to exclude specific fields from Serialization without annotationshaystack isn't indexing my multivalueWhat is wrong with my models.py?Permission checks in DRF viewsets are not working rightSerializing custom related field in DRFDjango-Rest-Framework - How to serialize queryset from an unrelated model as nested serializerCustomer User Authentication error : AttributeError: Manager isn't available; 'auth.User' has been swapped for 'user_management.CustomUser'Get nested serialized data as oneGot “ValueError: invalid literal for int() with base 10: 'Trancel'” when using two paramenters in detailview in DjangoHow to implement update_or_create inside create method of ModelSerializer



.everyoneloves__top-leaderboard:empty,.everyoneloves__mid-leaderboard:empty,.everyoneloves__bot-mid-leaderboard:empty height:90px;width:728px;box-sizing:border-box;








0















serializer



class CarrGetOrderDetails(serializers.Serializer):
order = CarrGetOrderDetail(required=False)
template = CarrGetOrderDetailTemplate(required=False, many=True)
extra_fields = CarrGetOrderDetailExtraFields(required=False, many=True)


View File



class CarrierOrderDetails(APIView):
permission_classes = (IsAuthenticated,)

def get(self, request):
order_id = request.GET['order_id']
#order_obj = Order.objects.filter(id=order_id)

obj = self.get_objects(order_id)
#print('#####',obj)
serializ = CarrGetOrderDetails(obj, many=True)
return Response(serializ.data)

def get_objects(self, order_obj):
model1 = Order.objects.filter(id=order_obj)
model2 = OrderTemplate.objects.filter(id=1)
model3 = OrderExtraField.objects.filter(id=1)
obj = 'order': model1, 'template': model2, 'extra_fields': model3
return obj


here i'm try to hit multiple serializer objects but got null data in serializer.data



Output



[
,
,

]









share|improve this question






























    0















    serializer



    class CarrGetOrderDetails(serializers.Serializer):
    order = CarrGetOrderDetail(required=False)
    template = CarrGetOrderDetailTemplate(required=False, many=True)
    extra_fields = CarrGetOrderDetailExtraFields(required=False, many=True)


    View File



    class CarrierOrderDetails(APIView):
    permission_classes = (IsAuthenticated,)

    def get(self, request):
    order_id = request.GET['order_id']
    #order_obj = Order.objects.filter(id=order_id)

    obj = self.get_objects(order_id)
    #print('#####',obj)
    serializ = CarrGetOrderDetails(obj, many=True)
    return Response(serializ.data)

    def get_objects(self, order_obj):
    model1 = Order.objects.filter(id=order_obj)
    model2 = OrderTemplate.objects.filter(id=1)
    model3 = OrderExtraField.objects.filter(id=1)
    obj = 'order': model1, 'template': model2, 'extra_fields': model3
    return obj


    here i'm try to hit multiple serializer objects but got null data in serializer.data



    Output



    [
    ,
    ,

    ]









    share|improve this question


























      0












      0








      0








      serializer



      class CarrGetOrderDetails(serializers.Serializer):
      order = CarrGetOrderDetail(required=False)
      template = CarrGetOrderDetailTemplate(required=False, many=True)
      extra_fields = CarrGetOrderDetailExtraFields(required=False, many=True)


      View File



      class CarrierOrderDetails(APIView):
      permission_classes = (IsAuthenticated,)

      def get(self, request):
      order_id = request.GET['order_id']
      #order_obj = Order.objects.filter(id=order_id)

      obj = self.get_objects(order_id)
      #print('#####',obj)
      serializ = CarrGetOrderDetails(obj, many=True)
      return Response(serializ.data)

      def get_objects(self, order_obj):
      model1 = Order.objects.filter(id=order_obj)
      model2 = OrderTemplate.objects.filter(id=1)
      model3 = OrderExtraField.objects.filter(id=1)
      obj = 'order': model1, 'template': model2, 'extra_fields': model3
      return obj


      here i'm try to hit multiple serializer objects but got null data in serializer.data



      Output



      [
      ,
      ,

      ]









      share|improve this question
















      serializer



      class CarrGetOrderDetails(serializers.Serializer):
      order = CarrGetOrderDetail(required=False)
      template = CarrGetOrderDetailTemplate(required=False, many=True)
      extra_fields = CarrGetOrderDetailExtraFields(required=False, many=True)


      View File



      class CarrierOrderDetails(APIView):
      permission_classes = (IsAuthenticated,)

      def get(self, request):
      order_id = request.GET['order_id']
      #order_obj = Order.objects.filter(id=order_id)

      obj = self.get_objects(order_id)
      #print('#####',obj)
      serializ = CarrGetOrderDetails(obj, many=True)
      return Response(serializ.data)

      def get_objects(self, order_obj):
      model1 = Order.objects.filter(id=order_obj)
      model2 = OrderTemplate.objects.filter(id=1)
      model3 = OrderExtraField.objects.filter(id=1)
      obj = 'order': model1, 'template': model2, 'extra_fields': model3
      return obj


      here i'm try to hit multiple serializer objects but got null data in serializer.data



      Output



      [
      ,
      ,

      ]






      django serialization django-models django-rest-framework






      share|improve this question















      share|improve this question













      share|improve this question




      share|improve this question








      edited Mar 22 at 7:54









      Dany

      2,1901721




      2,1901721










      asked Mar 22 at 5:43









      kriteshkritesh

      12




      12






















          1 Answer
          1






          active

          oldest

          votes


















          1














          You are initializing your serializer with many=True, so it is expecting a list of objects. You should either pass in a list of objects as the first argument to the serializer class constructor or remove the many=True kwarg.



          Also, since you are passing in a dictionary, I would use the data=... kwarg instead of the first argument which is instance.



          As a quick test, you can perform the following modification:



          obj = self.get_objects(order_id)
          serializ = CarrGetOrderDetails(obj, many = True)


          obj = self.get_objects(order_id)
          serializ = CarrGetOrderDetails(data=[obj], many = True)


          References



          • DRF Serializer Documentation

          • serializers.py:BaseSerializer





          share|improve this answer























          • thanks for reply!! i tried to make change but problem is Invalid data. Expected a dictionary, but got QuerySet.

            – kritesh
            Mar 22 at 7:30












          • Now you are onto the next issue. Your order field is many=False, but you are passing a list of objects via queryset. You can either make the field many=True or only provide it a single object by appending .first() to the order filter in your get objects function.

            – Joshua Taylor Eppinette
            Mar 22 at 7:46












          Your Answer






          StackExchange.ifUsing("editor", function ()
          StackExchange.using("externalEditor", function ()
          StackExchange.using("snippets", function ()
          StackExchange.snippets.init();
          );
          );
          , "code-snippets");

          StackExchange.ready(function()
          var channelOptions =
          tags: "".split(" "),
          id: "1"
          ;
          initTagRenderer("".split(" "), "".split(" "), channelOptions);

          StackExchange.using("externalEditor", function()
          // Have to fire editor after snippets, if snippets enabled
          if (StackExchange.settings.snippets.snippetsEnabled)
          StackExchange.using("snippets", function()
          createEditor();
          );

          else
          createEditor();

          );

          function createEditor()
          StackExchange.prepareEditor(
          heartbeatType: 'answer',
          autoActivateHeartbeat: false,
          convertImagesToLinks: true,
          noModals: true,
          showLowRepImageUploadWarning: true,
          reputationToPostImages: 10,
          bindNavPrevention: true,
          postfix: "",
          imageUploader:
          brandingHtml: "Powered by u003ca class="icon-imgur-white" href="https://imgur.com/"u003eu003c/au003e",
          contentPolicyHtml: "User contributions licensed under u003ca href="https://creativecommons.org/licenses/by-sa/3.0/"u003ecc by-sa 3.0 with attribution requiredu003c/au003e u003ca href="https://stackoverflow.com/legal/content-policy"u003e(content policy)u003c/au003e",
          allowUrls: true
          ,
          onDemand: true,
          discardSelector: ".discard-answer"
          ,immediatelyShowMarkdownHelp:true
          );



          );













          draft saved

          draft discarded


















          StackExchange.ready(
          function ()
          StackExchange.openid.initPostLogin('.new-post-login', 'https%3a%2f%2fstackoverflow.com%2fquestions%2f55293539%2fhow-to-get-data-from-multiple-nested-serializer%23new-answer', 'question_page');

          );

          Post as a guest















          Required, but never shown

























          1 Answer
          1






          active

          oldest

          votes








          1 Answer
          1






          active

          oldest

          votes









          active

          oldest

          votes






          active

          oldest

          votes









          1














          You are initializing your serializer with many=True, so it is expecting a list of objects. You should either pass in a list of objects as the first argument to the serializer class constructor or remove the many=True kwarg.



          Also, since you are passing in a dictionary, I would use the data=... kwarg instead of the first argument which is instance.



          As a quick test, you can perform the following modification:



          obj = self.get_objects(order_id)
          serializ = CarrGetOrderDetails(obj, many = True)


          obj = self.get_objects(order_id)
          serializ = CarrGetOrderDetails(data=[obj], many = True)


          References



          • DRF Serializer Documentation

          • serializers.py:BaseSerializer





          share|improve this answer























          • thanks for reply!! i tried to make change but problem is Invalid data. Expected a dictionary, but got QuerySet.

            – kritesh
            Mar 22 at 7:30












          • Now you are onto the next issue. Your order field is many=False, but you are passing a list of objects via queryset. You can either make the field many=True or only provide it a single object by appending .first() to the order filter in your get objects function.

            – Joshua Taylor Eppinette
            Mar 22 at 7:46
















          1














          You are initializing your serializer with many=True, so it is expecting a list of objects. You should either pass in a list of objects as the first argument to the serializer class constructor or remove the many=True kwarg.



          Also, since you are passing in a dictionary, I would use the data=... kwarg instead of the first argument which is instance.



          As a quick test, you can perform the following modification:



          obj = self.get_objects(order_id)
          serializ = CarrGetOrderDetails(obj, many = True)


          obj = self.get_objects(order_id)
          serializ = CarrGetOrderDetails(data=[obj], many = True)


          References



          • DRF Serializer Documentation

          • serializers.py:BaseSerializer





          share|improve this answer























          • thanks for reply!! i tried to make change but problem is Invalid data. Expected a dictionary, but got QuerySet.

            – kritesh
            Mar 22 at 7:30












          • Now you are onto the next issue. Your order field is many=False, but you are passing a list of objects via queryset. You can either make the field many=True or only provide it a single object by appending .first() to the order filter in your get objects function.

            – Joshua Taylor Eppinette
            Mar 22 at 7:46














          1












          1








          1







          You are initializing your serializer with many=True, so it is expecting a list of objects. You should either pass in a list of objects as the first argument to the serializer class constructor or remove the many=True kwarg.



          Also, since you are passing in a dictionary, I would use the data=... kwarg instead of the first argument which is instance.



          As a quick test, you can perform the following modification:



          obj = self.get_objects(order_id)
          serializ = CarrGetOrderDetails(obj, many = True)


          obj = self.get_objects(order_id)
          serializ = CarrGetOrderDetails(data=[obj], many = True)


          References



          • DRF Serializer Documentation

          • serializers.py:BaseSerializer





          share|improve this answer













          You are initializing your serializer with many=True, so it is expecting a list of objects. You should either pass in a list of objects as the first argument to the serializer class constructor or remove the many=True kwarg.



          Also, since you are passing in a dictionary, I would use the data=... kwarg instead of the first argument which is instance.



          As a quick test, you can perform the following modification:



          obj = self.get_objects(order_id)
          serializ = CarrGetOrderDetails(obj, many = True)


          obj = self.get_objects(order_id)
          serializ = CarrGetOrderDetails(data=[obj], many = True)


          References



          • DRF Serializer Documentation

          • serializers.py:BaseSerializer






          share|improve this answer












          share|improve this answer



          share|improve this answer










          answered Mar 22 at 6:04









          Joshua Taylor EppinetteJoshua Taylor Eppinette

          1656




          1656












          • thanks for reply!! i tried to make change but problem is Invalid data. Expected a dictionary, but got QuerySet.

            – kritesh
            Mar 22 at 7:30












          • Now you are onto the next issue. Your order field is many=False, but you are passing a list of objects via queryset. You can either make the field many=True or only provide it a single object by appending .first() to the order filter in your get objects function.

            – Joshua Taylor Eppinette
            Mar 22 at 7:46


















          • thanks for reply!! i tried to make change but problem is Invalid data. Expected a dictionary, but got QuerySet.

            – kritesh
            Mar 22 at 7:30












          • Now you are onto the next issue. Your order field is many=False, but you are passing a list of objects via queryset. You can either make the field many=True or only provide it a single object by appending .first() to the order filter in your get objects function.

            – Joshua Taylor Eppinette
            Mar 22 at 7:46

















          thanks for reply!! i tried to make change but problem is Invalid data. Expected a dictionary, but got QuerySet.

          – kritesh
          Mar 22 at 7:30






          thanks for reply!! i tried to make change but problem is Invalid data. Expected a dictionary, but got QuerySet.

          – kritesh
          Mar 22 at 7:30














          Now you are onto the next issue. Your order field is many=False, but you are passing a list of objects via queryset. You can either make the field many=True or only provide it a single object by appending .first() to the order filter in your get objects function.

          – Joshua Taylor Eppinette
          Mar 22 at 7:46






          Now you are onto the next issue. Your order field is many=False, but you are passing a list of objects via queryset. You can either make the field many=True or only provide it a single object by appending .first() to the order filter in your get objects function.

          – Joshua Taylor Eppinette
          Mar 22 at 7:46




















          draft saved

          draft discarded
















































          Thanks for contributing an answer to Stack Overflow!


          • Please be sure to answer the question. Provide details and share your research!

          But avoid


          • Asking for help, clarification, or responding to other answers.

          • Making statements based on opinion; back them up with references or personal experience.

          To learn more, see our tips on writing great answers.




          draft saved


          draft discarded














          StackExchange.ready(
          function ()
          StackExchange.openid.initPostLogin('.new-post-login', 'https%3a%2f%2fstackoverflow.com%2fquestions%2f55293539%2fhow-to-get-data-from-multiple-nested-serializer%23new-answer', 'question_page');

          );

          Post as a guest















          Required, but never shown





















































          Required, but never shown














          Required, but never shown












          Required, but never shown







          Required, but never shown

































          Required, but never shown














          Required, but never shown












          Required, but never shown







          Required, but never shown







          Popular posts from this blog

          Kamusi Yaliyomo Aina za kamusi | Muundo wa kamusi | Faida za kamusi | Dhima ya picha katika kamusi | Marejeo | Tazama pia | Viungo vya nje | UrambazajiKuhusu kamusiGo-SwahiliWiki-KamusiKamusi ya Kiswahili na Kiingerezakuihariri na kuongeza habari

          SQL error code 1064 with creating Laravel foreign keysForeign key constraints: When to use ON UPDATE and ON DELETEDropping column with foreign key Laravel error: General error: 1025 Error on renameLaravel SQL Can't create tableLaravel Migration foreign key errorLaravel php artisan migrate:refresh giving a syntax errorSQLSTATE[42S01]: Base table or view already exists or Base table or view already exists: 1050 Tableerror in migrating laravel file to xampp serverSyntax error or access violation: 1064:syntax to use near 'unsigned not null, modelName varchar(191) not null, title varchar(191) not nLaravel cannot create new table field in mysqlLaravel 5.7:Last migration creates table but is not registered in the migration table

          은진 송씨 목차 역사 본관 분파 인물 조선 왕실과의 인척 관계 집성촌 항렬자 인구 같이 보기 각주 둘러보기 메뉴은진 송씨세종실록 149권, 지리지 충청도 공주목 은진현