-1

データベースから返されるオブジェクトのグループの値を出力したいと考えています。

私は次のように試しました、

Products = productBll.listProduct(params)
print Products.__dict__

次のように表示されます。

{'_result_cache': [Product: Product object, Product: Product object]}

しかし、私がこのようにやっているとき、

for prd in Products:
    print prd.__dict__

Products オブジェクトのすべてのコンテンツを表示しています

{'product_price': 0.0, 'right_side_min_depth': 0.0, 'short_description': u'', 'left_side_min_depth': 0.0, 'max_depth': 0.0, 'height_scale': 2.0, 'left_side_max_depth': 0.0, 'is_hinges': u'No', 'max_height': 1.04}
{'product_price': 0.0, 'right_side_min_depth': 0.0, 'short_description': u'', 'left_side_min_depth': 0.0, 'max_depth': 1000.0, 'height_scale': 1000.0, 'left_side_max_depth': 0.0, 'is_hinges': u'No', 'max_height': 1000.0}

しかし、for ループを使用せずに上記の結果が必要です。

1行のコードでそれを行う方法はありますか?

4

2 に答える 2

1

探しているのがワンライナーだけの場合は、次のとおりです。

Products = productBll.listProduct(params)
print [prd.__dict__ for prd in Products]
于 2013-08-29T14:14:48.273 に答える
1

を使ってみることができますvalues()Productsあなたのモデルがあなたができると仮定して

Product.objects.filter(your_filter_criteria).values()

これにより、選択したアイテムごとの辞書のリストが表示されます。

于 2013-08-29T12:02:50.033 に答える