2015-03-31 46 views
0

的repr當使用mongoengine和django ORM時,會引發以下異常。無法獲取<class'mongoengine.queryset.queryset.QuerySet'>

Unable to get repr for <class 'mongoengine.queryset.queryset.QuerySet'> 

奇怪的是,它是一臺機器上運行沒有引發此錯誤

模型如下(在兩個安裝所需的軟件包後):

class Purchase(Document): 
_id = DynamicField(primary_key=True) 
customer_id = IntField() 
product_id = IntField() 
price = DynamicField() 
page = IntField() 
name = DynamicField() 

和異常拋出時:

Tags.objects.all()

我看了網上找到這個問題,我找不到答案。

任何人都知道什麼可能會導致此? (我猜模塊版本之間的差異)

回答

1

你需要實現類像__repr__方法:

class Purchase(Document): 
    enter code here`_id = DynamicField(primary_key=True) 
    customer_id = IntField() 
    product_id = IntField() 
    price = DynamicField() 
    page = IntField() 
    name = DynamicField() 

    def __repr__(self): 
     return 'Customer ID: ' + str(self.custmer.id)