2013-05-13 132 views
0

這是我的models.py*** ValueError異常:無效的字面INT()基數爲10:與shopify應用

class ShopifyUserProfile(models.Model): 
    shop_user = models.ForeignKey(UserProfile) 
    .... 

我正在特林保存其對象views.py

shop=shopify.Shop.current() 
    saved = ShopifyUserProfile.objects.get_or_create(shop_user.user = shop.attributes['shop_owner'], shop_name = shop.attributes['name'],.... etc) 

當我特林保存它會彈出一個錯誤

*** ValueError: invalid literal for int() with base 10: 'somevalue' 

我想:

temp = shop.attributes['shop_owner'] 
temp=temp.strip() 
temp=str(temp) 

仍然有相同的錯誤。

更新:它可能是shop_user是一個外鍵,我們可以明確分配。

class UserProfile(models.Model): 
    user = models.ForeignKey(User) 
    subscription = models.ForeignKey(Subscription) 

對於我甚至嘗試:

ShopifyUserProfile.objects.get_or_create(shop_user.user = temp) 

它會彈出新的錯誤:

*** SyntaxError: keyword can't be an expression (<stdin>, line 1) 

在哪裏,我錯了?

UPDATE(更正爲每俺們即現在傳遞對象),但仍得到相同的錯誤:

subs, stat = Subscription.objects.get_or_create(validity=datetime.now()+timedelta(days=30)) 
user, stat = UserProfile.objects.get_or_create(user=shop.attributes['shop_owner'],subscription=subs) 

saved = ShopifyUserProfile.objects.get_or_create(shop_user =user ,shop_name = shop.attributes['name'],... 

錯誤:

ipdb> user, stat = UserProfile.objects.get_or_create(user=shop.attributes['shop_owner'],subscription=subs) 
*** ValueError: invalid literal for int() with base 10: 'Jofin Joseph' 
+0

你真傳''somevalue''爲'INT()'?如果是這樣,你不能把這個文字轉換成一個int(不是沒有包裝+序號) – Amelia 2013-05-13 14:30:38

+1

Somevalue'實際* somevalue *或者你只是把它放在問題中?這是一個'int'無效轉換。 – 2013-05-13 14:31:29

+0

該值包含一個字符串值..說我的名字。通過int()傳遞它的感覺。沒有爲我消化。 – 2013-05-13 14:32:15

回答

1

您需要通過其中一個User對象或User.id值給您的ShopifyUserProfile.get_or_create致電。

在你的情況下,你傳遞一個字符串,然後傳遞給int,因爲Django需要一個整數。您必須爲其創建User對象,或者事先從數據庫中檢索相關的User對象。

您的電話應該是這樣的,如果你有User對象:

ShopifyUserProfile.objects.get_or_create(user=user_object, ...) 
相關問題