{% for user in request.user.membership_set.all %}
{{user.role}}
{% endfor %}
class Membership(models.Model):
user = models.OneToOneField(User, on_delete=models.CASCADE)
ROLE_CHOICES = (
('manager', 'Manager'),
('developer', 'Developer'),
('business_analyst', 'Business analyst'),
('system_analysts', 'System analysts'),
)
role = models.CharField(max_length=20, choices=ROLE_CHOICES,)
{{request.user.membership.role}}
ADMIN_REORDER = (
# Keep original label and models
'sites',
# Rename app
{'app': 'auth', 'label': 'Authorisation'},
# Reorder app models
{'app': 'auth', 'models': ('auth.User', 'auth.Group')},
# Exclude models
{'app': 'auth', 'models': ('auth.User', )},
# Cross-linked models
{'app': 'auth', 'models': ('auth.User', 'sites.Site')},
# models with custom name
{'app': 'auth', 'models': (
'auth.Group',
{'model': 'auth.User', 'label': 'Staff'},
)},
)
{% for comment in instance.comment_set.all %}
{{ comment }}
{% endfor %}
{% for item in comment %}
{{ item }}
{% endfor %}
# -*- coding: utf-8 -*-
from __future__ import unicode_literals
from django.db import models
from .managers import NewsQuerySet
class Product(models.Model):
is_published = models.BooleanField(
default=False,
verbose_name=u'Показывать на сайте',
)
title = models.CharField(
max_length=200,
verbose_name=u'Название',
)
objects = NewsQuerySet.as_manager()
class Meta:
verbose_name = u'Новость'
verbose_name_plural = u'Новости'
def __unicode__(self):
return self.title
# -*- coding: utf-8 -*-
from django.db import models
class NewsQuerySet(models.QuerySet):
def published(self):
return self.filter(is_published=True)
# -*- coding: utf-8 -*-
from django.views.generic import ListView, DetailView
from .models import News
class NewsList(ListView):
queryset = News.objects.published()
class NewsDetail(DetailView):
queryset = News.objects.published()