Django
3
Вклад в тег
{% 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()
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'},
)},
)