Answer the question
In order to leave comments, you need to log in
How to implement list of users by category Django 1.9?
I ask you to help with the implementation of the list of people by category, I am not familiar with django at all, I tried to google, but a lot of material is not written for dummies and therefore I do not fully understand the implementation. There are 2 models:
# coding: utf-8
from django.db import models
class Team(models.Model):
name = models.CharField(max_length=100, unique=True)
def __unicode__(self):
return self.name
class TeamUser(models.Model):
name = models.CharField(max_length=100, unique=True)
description = models.CharField(max_length=500)
image = models.ImageField("image", upload_to='avatars', blank=False)
team = models.ForeignKey(Team)
def __unicode__(self):
return self.name
Answer the question
In order to leave comments, you need to log in
views.py
from .models import Team
from django.views.generic import ListView
class TeamList(ListView):
model = Team
{% for item in team_list %}
{{item.name}}<br>
{% for user in item.team.all %}
{{user.name}}<br>
{% endfor %}
{% endfor %}
Didn't find what you were looking for?
Ask your questionAsk a Question
731 491 924 answers to any question