I would like to fetch data from a PostgreSQL using Django models/managers and use this data to render my frontend furthermore. I have the following plain simple example where I just get the defined privatekey value in return but not the other information from the table.
Estimated outcome:
I would like to get all elements of a single row as one object.
Models.py:
from django.db import models
import uuid
# Create your models here.
class AccountInformationManager(models.Manager):
pass
class AccountInformation(models.Model):
version = models.CharField(max_length=20, blank=False)
DID = models.UUIDField(primary_key=True, default=uuid.uuid4, editable=False)
accountNumber = models.IntegerField(blank=False)
broker = models.CharField(max_length=50, blank=False)
leverage = models.CharField(max_length=10, blank=False)
account_balance = models.FloatField(max_length=15, blank=False)
account_profit = models.FloatField(max_length=15, blank=False)
account_equity = models.FloatField(max_length=15, blank=False)
account_margin = models.FloatField(max_length=15, blank=False)
account_margin_free = models.FloatField(max_length=15, blank=False)
account_margin_level = models.FloatField(max_length=15, blank=False)
account_currency = models.CharField(max_length=20, blank=False)
objects = models.Manager()
class Meta:
db_table = 'AccountInfo'
Query.py:
from django.db import models
import sys
sys.path.insert(0, r"C:\Users\Jonas\Desktop\Dashex")
import os
os.environ['DJANGO_SETTINGS_MODULE'] = 'Dashex.settings'
import django
django.setup()
from Dashboard.models import AccountInformation
//// query data
account_information = AccountInformation.objects.all()
print(account_information)
Printed Output:
<QuerySet [<AccountInformation: AccountInformation object (30e61aec-0f6e-4fa0-8c1b-eb07f9347c1f)>, <AccountInformation: AccountInformation object (8b46c7c7-1bc8-4736-8dc5-7d5f012d594b)>]>
Process finished with exit code 0
Why it doesn't return the whole data from the table like broker, accountNumberetc.?
linked question:
Additionally, if I use AJAX + Javascript to render my frontend, would I then call the query.py script within my Ajax Url to fetch the data from the DB and render the frontend?
