2013-05-13 129 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, ...) 
相关问题