title: Django & Mongoengine get data from embedded document?
body: <p>I am having trouble retrieving data from the embedded document in mongoengine.</p>
  
  <p>models.py</p>
  
  <pre><code>from mongoengine import Document, EmbeddedDocument, fields
  
  
  
  class ProductFields(EmbeddedDocument):
      key_name    = fields.StringField(required=True)
      value   = fields.DynamicField(required=True)
  
  class Product(Document):
      name        = fields.StringField(required=True)
      description = fields.StringField(required=True, null=True)
      fields      = fields.ListField(fields.EmbeddedDocumentField(ProductFields))
  </code></pre>
  
  <p>views.py</p>
  
  <pre><code>class ProductListView(APIView):
  
      def get(self, request):
          # list_products = Product.objects.all()
          result=[]
          productfields = ProductFields
          for product in Product.objects:
              data={
                  "name":product.name,
                  "description":product.description,
                  # "key":product.fields.key_name,
                  # "value":ProductFields.value,
              }
              print (data)
              # print(productfields.key_name)
              result.append(data)
          return Response({"products":result,"message":"list of products.","requestStatus":1},status=status.HTTP_200_OK)
  </code></pre>
  
  <p>Output:</p>
  
  <pre><code>{
          "description": "test description",
          "name": "product1"
          "fields":[ 
             { "key_name" : value},
             { "key_name" : value},
             ]
  }
  </code></pre>
  
  <p>How do I get the above-desired output? Print function doesn't work because mongoengine returns object and not the value.</p>