how can I display or return a instance of a django model by using another instance(which is primary key)

90 Views Asked by At

views.py I have Wallet class. with fields user and Walletname. When a new user is registered, a new Wallet object is created by signal. What I would like to do is display Walletname of the current logged in user.

I tried filtering but I got error saying %s is expected integer value. However I have never created a instance named as id

1

There are 1 best solutions below

7
On

In your views try doing:

wallet = Wallet.objects.get(user=request.user)

then if you pass this to your front end you can display the name by doing:

{{wallet.Walletname}}