C
C
Cube2015-12-23 14:54:35
Django
Cube, 2015-12-23 14:54:35

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

It is necessary to implement lists of people who belong to one of the teams. That is:
Team (1):
Vasily Petushkin,
Andrey Sobachkin
Team (2):
Dima Medvedev,
Zhenya Kotok.

Answer the question

In order to leave comments, you need to log in

2 answer(s)
G
German Jet, 2015-12-23
@liveunit

views.py

from .models import Team
from django.views.generic import ListView

class TeamList(ListView):
    model = Team

template
{% for item in team_list %}
  {{item.name}}<br>
    {% for user in item.team.all %}
      {{user.name}}<br>
    {% endfor %}
{% endfor %}

V
Vladimir, 2015-12-23
@vintello

why is Dima Medvedev number two on your team? messy

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question