Answer the question
In order to leave comments, you need to log in
How to filter a selection in a template?
I have:
class Data(models.Model):
user = models.ForeignKey(settings.AUTH_USER_MODEL, verbose_name=_('User'))
number = models.CharField(_('Number'), unique=True, max_length=6)
class Wallet(models.Model):
user = models.ForeignKey(settings.AUTH_USER_MODEL, verbose_name=_('User'))
data = models.ForeignKey(m.Data, null=True, verbose_name=_('Data'))
class DataListView(LoginRequiredMixin, TemplateView, BaseContextMixin):
template_name = "data/list.html"
login_url = reverse_lazy('users:login')
def get_context_data(self, **kwargs):
context = super(DataListView, self).get_context_data(**kwargs)
context['my_data'] = self.request.user.data_set.all()
return context
{% for one in my_data %}
{% endfor %}
{% for wallet in one.wallet_set.all %}
{% endfor %}
Answer the question
In order to leave comments, you need to log in
Didn't find what you were looking for?
Ask your questionAsk a Question
731 491 924 answers to any question