queryset.filter(**params).only('dates', 'type_date').select_related(*select_rel).order_by('-dates', '-create')
queryset.values('dates').annotate(count=Count('dates')).order_by() # Сбросил сортировку
SELECT `dates`, COUNT(`dates`) AS `count`
FROM `gigdate_dateall`
WHERE (`dates` IN (2015-08-31, 2015-09-01, 2015-09-02, 2015-09-03) AND `type_date` = 0)
GROUP BY `dates` ORDER BY NULL
dates = models.DateField(_(u'Дата календаря'), blank=False)
...
class Meta:
ordering = ['-dates', '-create']
SELECT `dates`, COUNT(`dates`) AS `count`
FROM `gigdate_dateall`
WHERE (`dates` IN (2015-08-31, 2015-09-01, 2015-09-02, 2015-09-03) AND `type_date` = 0)
GROUP BY `dates`, `create` ORDER BY `dates` DESC, `create` DESC
class TextTemplate(models.Model):
....
def get_absolute_file_upload_url(self):
return MEDIA_URL + self.file_upload.url
#urls.py
...
urlpatterns = patterns(
'',
url(r'^text-template/(?P<primary_key>\d+)/$', get_tt),
url(r'^text-template/$', get_all_tt),
)
...
#view.py
def get_tt(request, primary_key):
tt_item = TextTemplate.objects.get(pk=primary_key)
# or
# tt_item = get_or_404(TextTemplate, pk=primary_key)
print tt_item.file_upload.url
return render('t.html', {'tt': tt_item})
def get_all_tt(request):
tt_all = TextTemplate.objects.all()
for tt_item in tt_all:
print tt_item.file_upload.url
return render('tt-all.html', {'tt': tt_all})
#t.html
<img src="{{ MEDIA_URL }}{{ tt.url }}">
<br>
<img src="{{ tt.get_absolute_file_upload_url }}">
#tt-all.html
{% for tt in tt_all %}
<img src="{{ tt.get_absolute_file_upload_url }}">
{% endfor %}
pip install django-haystack
pip install -e git+https://github.com/toastdriven/django-haystack.git@master#egg=django-haystack
haystack
to your INSTALLED_APPS
.search_indexes.py
files for your models.SearchIndex
via autodiscover
.haystack.urls
to your URLconf.