from django.views.generic import ListView
class NewsList(ListView):
model = News
paginate_by = 5
News.objects.all()[:5]
class News(Model):
# Твоя модель новостей
@classmethod
def last_five(cls):
return cls.objects.all()[:5]
return render(request, 'template.html', {'News': News})
<div class="my-very-own-news">
{% for news in News.last_five %}
{{ news }}
{% endfor %}
</div>
{% for album in albums %}
<div class="album-{{ album.pk }}">
{% for image in album.image_set.all %}
<div class="image-{{ image.pk }}>
<img src="{{ image.image.url }}}" alt="Image was here"/>
</div>
{% endfor %}
</div>
{% endfor %}
url(r'^blog/$', 'module.views.blog', name='blog'),
<a href="{% url 'blog' %}">Go ahead</a>
def you_func(d):
result = set()
for k, v in d.items():
r, g, b = k.index('R'), k.index('G'), k.index('B')
for color in v:
result.add((color[r], color[g], color[b]))
return result
def f(d):
return {(c[k.index('R')], c[k.index('G')], c[k.index('B')]) for k, v in d.items() for c in v}
from datetime import datetime
import requests
now = datetime.now().strftime('%Y-%m-%d_%H-%M')
string_that_you_need = now + '.mp4' # Сейчас это выглядит, как "2015-04-29_10-59.mp4"
request = requests.get('http://site.that/you/need/%s' % string_that_you_need)
f = open('file.mp4', 'wb')
f.write(request.content)
f.close()