1

I am a beginner in Django and coding in general. I know that this must be an easy thing to do but I have been struggling with this for days.

This is my model:

class Bal(models.Model):
balance = models.IntegerField(default='5000')

def __int__(self):
    return "{}, {}".format(self.pk, self.balance)

View:

def add_stock(request):
import requests
...

bala = Bal.objects.get(pk=2)

'''

    return render(request, 'stocktrader/add_stock.html', {'ticker': ticker, 'output': output, 'bala': bala})

in the html page:

<h4>Balance: {{ bala }}</h4>

The output on the web page is:

Balance: Bal object (2)

Where "Bal object(2)" is I need it to display a number.

The table in the database has one 'balance' entry for 5000 and it has an id if 2. I just don't understand how to get the value of '5000' to display instead of 'Bal object (2)'.

1 Answer 1

2

Maybe

<h4>Balance: {{ bala.balance }}</h4>

should work? :)

Sign up to request clarification or add additional context in comments.

2 Comments

thank you very much. I knew it would be something simple.
Wellcome. You have to take a look at ORM. By the way it could be nice if you select this as answer if it worked. :)

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.