class Album(models.Model):
name = models.CharField(max_length=35)
owner = models.ForeignKey(User)
create_date = models.DateTimeField(auto_now_add=True)
class Image(models.Model):
album = models.ForeignKey(Image, related_name='images')
image = models.ImageField()
upload_date = models.DateTimeField(auto_now_add=True)
slug = models.SlugField()
views = models.IntegerField(default=0)
#
def get_paginate_by(self, queryset):
"""
Get the number of items to paginate by, or ``None`` for no pagination.
"""
try:
self.paginate_by = int(
self.request.GET.get('paginate_by', self.paginate_by))
except ValueError:
logger.error('Some stupid person use not int for paginate_by')
return self.paginate_by
<form method="get">
<select id="input-limit" name="paginate_by" class="form-control">
<option value="4" selected="selected">4</option>
<option value="8">8</option>
<option value="25">25</option>
</select>
<button type="submit">Paginate by</button>
</form>
export $SITE_NAME=www.foo.bar
cd $HOME
cd
{{ text | safe }}
https://docs.djangoproject.com/en/1.10/ref/templat... sudo apt-get install uwsgi uwsgi-plugin-python3
virtualenv tdjango -p `which python3`
source tdjango/bin/activate
pip install django
django-admin startproject progtdjango
uwsgi --http-socket :8000 --plugins python3 \
--module=progtdjango.wsgi:application \
--home `pwd`/tdjango \
--chdir `pwd`/progtdjango
sudo pip install virtualenv virtualenvwrapper
и вообще sudo pip install
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8">
<title>Title</title>
<script src="https://code.jquery.com/jquery-1.11.3.js"></script>
</head>
<body>
<form action="{% url form_url %}" class="js-feedback_form" method="post">
{% csrf_token %}
{{ form }}
<button type="submit">Foo</button>
</form>
<script>
// using jQuery
function getCookie(name) {
var cookieValue = null;
if (document.cookie && document.cookie !== '') {
var cookies = document.cookie.split(';');
for (var i = 0; i < cookies.length; i++) {
var cookie = jQuery.trim(cookies[i]);
// Does this cookie string begin with the name we want?
if (cookie.substring(0, name.length + 1) === (name + '=')) {
cookieValue = decodeURIComponent(cookie.substring(name.length + 1));
break;
}
}
}
return cookieValue;
}
var csrftoken = getCookie('csrftoken');
var $feedback_form = $('.js-feedback_form');
$feedback_form.submit(function (e) {
e.preventDefault();
$.ajax({
method: 'post',
url: $feedback_form.attr('action'),
data: $feedback_form.serialize(),
success: function(data) {
alert('Data send');
}
});
})
</script>
</body>
</html>