这是我的models.py
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)
我哪里错了??
更新(根据 ans 更正,即现在传递对象)但仍然出现相同的错误:
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'