これは私の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'