Answer the question
In order to leave comments, you need to log in
How to get filtered customer data in django?
portfolio model
class Portfolio(models.Model):
client = models.ForeignKey(Client, on_delete=models.CASCADE, related_name='portfolio')
name = models.CharField('название', max_length=255)
initial_investment_amount = models.PositiveIntegerField('начальная сумма инвестиций',)
investment_horizon = models.PositiveIntegerField('инвестиционный горизонт',)
type_investor = models.PositiveSmallIntegerField('тип инвестора', choices=TYPE_INVESTOR)
currency = models.PositiveSmallIntegerField('валюта', choices=CURRENCY)
maximum_allowable_drawdown = models.PositiveIntegerField('максимально допустимая просадка',)
type_according_risk_reward = models.PositiveSmallIntegerField('тип по соотношению риска/прибыли', choices=TYPE_RISK)
focus = models.PositiveSmallIntegerField('фокус', choices=FOCUS)
types_assets = models.PositiveSmallIntegerField('тип акций', choices=TYPE_ASSETS)
ETF = models.PositiveSmallIntegerField(choices=ETF)
active = models.BooleanField()
all_clients = Client.objects.filter(investmen=investmen)
{% for i in all_clients %}
{{ i.portfolio.count }}
{% endfor %}
Answer the question
In order to leave comments, you need to log in
With filters
@register.filter
def get_active_portfolio_items(client):
return Portfolio.objects.filter(client=client, active=True)
{% for port in i|get_active_portfolio_items%}
{{ port}}
{% endfor %}
You can send already filtered data to the template context -all_clients.filter(active=True)
Didn't find what you were looking for?
Ask your questionAsk a Question
731 491 924 answers to any question