def get(self, request, *args, **kwargs):
dataset = self.resource_class.export(queryset=self.get_queryset()) # тут поменяй логику получения csv файла на свою
response = StreamingHttpResponse(dataset, content_type='text/csv')
response['Content-Disposition'] = 'attachment; filename="export.csv"' # export.csv меняй на то имя какое тебе необходимо
return response
select distinct on (section)
section,
characteristic,
change_date,
bool_value
from securities
where characteristic = 8328
group by id, section
order by section desc, change_date desc
section | characteristic | change_date | bool_value
---------+----------------+----------------------------+------------
c | 8328 | 2018-09-20 12:28:00.701+00 | f
b | 8328 | 2018-09-02 12:28:00.701+00 | t
a | 8328 | 2018-09-02 12:27:41.907+00 | f
(3 rows)
select distinct on (section)
section
from accounts_securities
where characteristic = 8328
group by id, section
order by section desc, change_date desc
from django.db import models
from django.utils.translation import ugettext_lazy as _
class SchoolClass(models.Model):
name = models.CharField(
_('Класс'),
max_length=10,
db_index=True,
unique=True,
help_text=_('Название класса.'),
)
class Meta:
verbose_name = _('Класс')
verbose_name_plural = _('Классы')
def __str__(self):
return self.name
class Pupil(models.Model):
first_name = models.CharField(
_('Имя'),
max_length=100,
db_index=True,
help_text=_('Имя учащегося.'),
)
last_name = models.CharField(
_('Фамилия'),
max_length=100,
db_index=True,
help_text=_('Фамилия учащегося.'),
)
school_class = models.ForeignKey(
to=SchoolClass, on_delete=models.CASCADE,
verbose_name=_('Класс'), related_name='pupils',
help_text=_('Название класса.'),
)
class Meta:
verbose_name = _('Ученик')
verbose_name_plural = _('Ученики')
indexes = (
models.Index(fields=['first_name', 'last_name']),
)
def __str__(self):
return self.full_name
@property
def full_name(self):
return '{} {}'.format(self.first_name, self.last_name)
class Schedule(models.Model):
ATTEND = 'attend'
ABSENT = 'absent'
STATUS_CHOICES = (
(ATTEND, 'Присутствовал'),
(ABSENT, 'Отсутствовал'),
)
pupil = models.ForeignKey(
to=Pupil, on_delete=models.CASCADE,
verbose_name=_('Ученик'), related_name='schedules',
help_text=_('Фамилия и имя учащегося.')
)
date = models.DateField(
_('Дата'),
db_index=True,
help_text=_('Дата.')
)
status = models.CharField(
_('Статус'), max_length=10,
choices=STATUS_CHOICES, default=ABSENT,
db_index=True,
help_text=_('Статус.')
)
class Meta:
verbose_name = _('Расписание')
verbose_name_plural = _('Расписания')
indexes = (
models.Index(fields=['date', 'status']),
)
unique_together = ('pupil', 'date',)
from django.contrib import admin
from schedule.models import (
SchoolClass,
Pupil,
Schedule
)
class PupilInLIne(admin.TabularInline):
model = Pupil
fields = ('first_name', 'last_name')
extra = 1
class ScheduleInLIne(admin.TabularInline):
model = Schedule
fields = ('date', 'status')
extra = 1
@admin.register(SchoolClass)
class SchoolClassAdmin(admin.ModelAdmin):
list_display = ('name',)
list_display_links = ('name',)
inlines = (PupilInLIne,)
list_filter = ('name',)
search_fields = ('name',)
@admin.register(Pupil)
class PupilAdmin(admin.ModelAdmin):
list_display = ('full_name', 'school_class')
list_display_links = ('full_name',)
inlines = (ScheduleInLIne,)
raw_id_fields = ('school_class',)
list_select_related = ('school_class',)
search_fields = ('first_name', 'last_name', 'school_class__name')
list_filter = ('school_class__name',)
class PupilScheduleDetailView(DetailView):
model = Pupil
template_name = 'pupil_schedule_detail.html'
def get_context_data(self, **kwargs):
context_data = super().get_context_data(**kwargs)
schedule_queryset = self.object.schedules.all().select_related(
'pupil'
).values(
'pupil__first_name',
'pupil__last_name',
'date', 'status'
)
context_data.update({
'schedules': schedule_queryset
})
return context_data
{% if schedules %}
<table>
{% for schedule in schedules %}
<tr>
<td>{{ schedule.pupil__first_name }} {{ schedule.pupil__last_name }}</td>
<td>{{ schedule.date }}</td>
<td>{{ schedule.status }}</td>
</tr>
{% endfor %}
</table>
{% else %}
<p>Данных нет!</p>
{% endif %}
from django.conf import settings
from django.conf.urls import include, url
from django.conf.urls.static import static
urlpatterns = [
url(r'^$', TemplateView.as_view(template_name='base.html'), name="home"),
# Django Admin, use {% url 'admin:index' %}
url(settings.ADMIN_URL, include(admin.site.urls)),
url(r'^accounts/', include('allauth.urls')),
# Your stuff: custom urls includes go here
]
urlpatterns += static(settings.MEDIA_URL, document_root=settings.MEDIA_ROOT)
urlpatterns += static(settings.STATIC_URL, document_root=settings.STATIC_ROOT)
<h1>Hello</h1>
{% load staticfiles %}
<!DOCTYPE html>
<html>
<head lang="en">
<meta charset="UTF-8">
<title>{% block title %}{% endblock %}</title>
<link rel="stylesheet" href="{% static 'css/reset.min.css' %}"/>
<link rel="stylesheet" href="{% static 'css/main.css' %}"/>
</head>
<body>
{% block header %}{% endblock %}
<script src="{% static 'js/main.js' %}"></script>
</body>
</html>
{% extends "base.html" %}
{% block title %}Index{% endblock %}
{% block header %}
{% with txt='1' %}
{% include "layouts/header.html" %}
{% endwith %}
{% endblock %}
<header>
<p>{{ txt }}</p>
</header>
{% extends "base.html" %}
{% block title %}Index{% endblock %}
{% block header %}
{% with txt='1' txt2='2' txt3='3' %}
{% include "layouts/header.html" %}
{% endwith %}
{% endblock %}
<header>
<p>{{ txt }}</p>
<p>{{ txt2 }}</p>
<p>{{ txt3 }}</p>
</header>