Answer the question
In order to leave comments, you need to log in
How to get all object data in django in template engine?
Good day.
The task is as follows:
There is a client model:
class Client(models.Model):
name = models.CharField(max_length=255)
class Portfolio(models.Model):
client = models.ForeignKey(Client, on_delete=models.CASCADE, related_name='portfolio')
name = models.CharField('название', max_length=255)
class Stock(models.Model):
portfolio = models.ForeignKey(Portfolio, on_delete=models.CASCADE, related_name='stock')
name = models.CharField(max_length=255, blank=True)
ticker = models.ForeignKey(Ticker, on_delete=models.CASCADE, related_name='ticker')
class Ticker(models.Model):
name = models.CharField(max_length=255)
class TickerValue(models.Model):
ticker = models.ForeignKey(Ticker, on_delete=models.CASCADE, related_name='ticker_value')
date = models.DateField()
closing_cost = models.FloatField()
{% for i in clients %}
{{ i.name }}
{% endfor %}
Answer the question
In order to leave comments, you need to log in
{% for client in clients %}
{% for portfolio in client.portfolio_set.all %}
{% for stock in portfolio.stock_set.all %}
{% for ticker_value in stock.ticker.tickervalue_set.all %}
{{ ticker_value.closing_cost }}
{% endfor %}
{% endfor %}
{% endfor %}
{% endfor %}
Didn't find what you were looking for?
Ask your questionAsk a Question
731 491 924 answers to any question