Это мой код, и я вижу ошибку "Django - Невозможно назначить" 2 ":" Wallet.coin "должен быть экземпляром" Coins "." , пожалуйста помоги. Я искал причину в течение 10 часов, я не могу решить. А может еще ошибки? Спасибо
views.py
def load_user_balance(request, wallet_id, imei):
try:
user = User.objects.get(imei=imei)
except ObjectDoesNotExist:
create = User.objects.create(imei=imei, wallet_mx=wallet_id)
create.save()
url_wallet = f"https://explorer-api.minter.network/api/v1/addresses/{wallet_id}"
response_wallet=requests.get(url_wallet).json()['data']
for coin in response_wallet['balances']:
coin_w = coin['coin']
amount_w = coin['amount']
coin_id_1 = Coins.objects.get(symbol=coin_w)
coin_id = coin_id_1.id
user_id = User.objects.get(imei=imei)
user_id_1 = user_id.id
obj, created = Wallet.objects.update_or_create(user_id_id=user_id_1, coin=coin_id, amount_w=amount_w, defaults={'user_id_id': user_id_1, 'coin': coin_id,
'amount_w': amount_w},
)
obj.save()
models.py
class Coins(models.Model):
name = models.CharField(max_length=150)
symbol = models.CharField(max_length=45)
crr = models.CharField(max_length=3)
class User(models.Model):
imei = models.CharField(max_length=100)
wallet_mx = models.CharField(max_length=50)
class Wallet(models.Model):
user_id = models.ForeignKey(User, on_delete=models.CASCADE)
coin = models.ForeignKey(Coins, on_delete=models.CASCADE)
amount_w = models.DecimalField(max_digits=19, decimal_places=4)
amount_d = models.DecimalField(max_digits=19, decimal_places=4)
cap_w = models.DecimalField(max_digits=19, decimal_places=4)
cap_d = models.DecimalField(max_digits=19, decimal_places=4)