Re: Django Pagination paginate dictionary of objects

2020-07-28 Thread jhabar singh
bro try to send a intended code

On Tue, Jul 28, 2020 at 5:16 PM Harvindar Singh Garcha <
garchaama...@gmail.com> wrote:

> I am new to Django, and trying to paginate a dictionary objects,
> However I am unable to so and not getting what's wrong with my code,
> Its still printing whole data on a single page. Above I have posted my
> View along with template code.
>
>
> class Search(ListView):
>  paginate_by = 5
>
>  def get(self, request):
>  if 'search' in request.GET:
>  search = request.GET['search']
>  url = '
> https://api.stackexchange.com/2.2/search/advanced?=stackoverflow'
>  params = dict(item.split("=") for item in search.split(","))
>  req = PreparedRequest()
>  req.prepare_url(url, params)
>  stackoverflow_url = req.url
>  response = requests.get(stackoverflow_url)
>  data = response.json()
>  #Data will be like this
>  # data={{'tag':'python','question':'some
> question'},{'tag':'java','question':'some question'}}
>  # n here is 2
>  paginator = Paginator(list(data), 5)
>  page_number = request.GET.get('search')
>  page_obj = paginator.get_page(page_number)
>  return render(request, 'stackoverflow.html', {
>  'data': data,
>  'page_obj': page_obj
>
>  })
>
>
>
>
>
>
>
>
> {%if data %}
> 
>  
> 
>  {% for key,value in data.items %}
>  
>  
> {{ value.title }}
> {{ value.creation_date }} 
>  Asked By  "{{value.owner_link}}">{{value.display_name }} 
>   >Read More   
>  {% endfor %}
>  
> 
> 
> 
> 
> {% if value.has_previous %}
>  first
> previous
> {% endif %}
>  Page {{ page_obj.number }} of {{
> page_obj.paginator.num_pages }}.
>  
>  {% if page_obj.has_next %}
>  next
> last 
>  {% endif %}
>  
>  
> {% else %}
>  No Results found :(
> {% endif %}
> {% endblock content %}
>
>
>
>
>
> --
> You received this message because you are subscribed to the Google Groups
> "Django users" group.
> To unsubscribe from this group and stop receiving emails from it, send an
> email to django-users+unsubscr...@googlegroups.com.
> To view this discussion on the web visit
> https://groups.google.com/d/msgid/django-users/f2aeb012-8bad-4234-9a4f-635fe1a8698ao%40googlegroups.com
> 
> .
>

-- 
You received this message because you are subscribed to the Google Groups 
"Django users" group.
To unsubscribe from this group and stop receiving emails from it, send an email 
to django-users+unsubscr...@googlegroups.com.
To view this discussion on the web visit 
https://groups.google.com/d/msgid/django-users/CAJ1QTg%3Dq-dCPgexPQmSZ5w8seqh71K-sByLei%2BXkQHs5soj6WA%40mail.gmail.com.


Re: Django Pagination

2020-06-01 Thread maninder singh Kumar
I think there might be a way around, below is the code modified for views.py

@login_required
def home_view(request):
"""Display all the post of friends and own posts on the dashboard"""
posts = Post.objects.order_by('-date_posted')
media: MEDIA_URL
# 'post':Post.objects.filter(Q(author=request.user) |
Q(author__from_user=request.user) |
Q(author__to_user=request.user)).order_by('-date_posted'),
paginator = Paginator(posts, 2)
page_number = request.GET.get('page')
try:
page_obj = paginator.page('page')
except PageNotAnInteger:
page_obj = paginator.page(1)
except EmptyPage:
page_obj = paginator.page(paginator.num_pages)
return render(request, 'post/home.html',{'page_obj': page_obj})

I think this might work !

regards
willy


On Mon, Jun 1, 2020 at 7:48 PM Akshat Zala  wrote:

> Dear Sir,
>
> it shows all the text on all the pages.
>
> if there are total 5 posts, then it  shows all the 5 posts on all the
> pages.
>
> Thanks,
>
> Akshat Zala
>
> On Saturday, 30 May 2020 20:54:35 UTC+5:30, maninder singh Kumar wrote:
>>
>> Views.py looks fine !
>>
>> regards
>> willy
>>
>>
>> On Sat, May 30, 2020 at 7:22 PM Akshat Zala  wrote:
>>
>>> Hello,
>>>
>>> I am finding it difficult to paginate through all the posts
>>>
>>> My views.py :
>>>
>>> @login_required
>>> def home_view(request):
>>> """Display all the post of friends and own posts on the dashboard"""
>>> posts = Post.objects.all().order_by('-date_posted')
>>> media: MEDIA_URL
>>> # 'post':Post.objects.filter(Q(author=request.user) |
>>> Q(author__from_user=request.user) |
>>> Q(author__to_user=request.user)).order_by('-date_posted'),
>>> paginator = Paginator(posts, 2)
>>> page_number = request.GET.get('page')
>>> page_obj = paginator.get_page(page_number)
>>> return render(request, 'post/home.html',{'page_obj': page_obj})
>>>
>>>
>>> and in template post/home.html:
>>>
>>> {% if is_paginated %}
>>> {% if page_obj.has_previous %}
>>> First
>>> arrow_left
>>> 
>>> {% endif %}
>>> {% for num in page_obj.paginator.page_range %}
>>> {% if page_obj.number == num %}
>>> {{ num }}
>>> {% elif num > page_obj.number|add:'-4' and num < page_obj.number|add:'4'
>>> %}
>>> {{ num }}
>>> 
>>> {% endif %}
>>> {% endfor %}
>>> {% if page_obj.has_next %}
>>> arrow_right
>>> Last
>>> {% endif %}
>>>
>>>
>>> Thanks
>>>
>>> Akshat Zala
>>>
>>> --
>>> You received this message because you are subscribed to the Google
>>> Groups "Django users" group.
>>> To unsubscribe from this group and stop receiving emails from it, send
>>> an email to django...@googlegroups.com.
>>> To view this discussion on the web visit
>>> https://groups.google.com/d/msgid/django-users/87c3f0db-3088-448c-b3c7-14450e8c2f5d%40googlegroups.com
>>> 
>>> .
>>>
>> --
> You received this message because you are subscribed to the Google Groups
> "Django users" group.
> To unsubscribe from this group and stop receiving emails from it, send an
> email to django-users+unsubscr...@googlegroups.com.
> To view this discussion on the web visit
> https://groups.google.com/d/msgid/django-users/c775d687-0773-4d09-86be-35e6f2cd55d2%40googlegroups.com
> 
> .
>

-- 
You received this message because you are subscribed to the Google Groups 
"Django users" group.
To unsubscribe from this group and stop receiving emails from it, send an email 
to django-users+unsubscr...@googlegroups.com.
To view this discussion on the web visit 
https://groups.google.com/d/msgid/django-users/CABOHK3T5A8JT%2BOe-Tt%3DAw4ZOff%2BwVWXO4EXMbkKtTUz2Y2spZg%40mail.gmail.com.


Re: Django Pagination

2020-06-01 Thread Akshat Zala
Dear Sir,

it shows all the text on all the pages.

if there are total 5 posts, then it  shows all the 5 posts on all the pages.

Thanks,

Akshat Zala

On Saturday, 30 May 2020 20:54:35 UTC+5:30, maninder singh Kumar wrote:
>
> Views.py looks fine !
>
> regards
> willy
>
>
> On Sat, May 30, 2020 at 7:22 PM Akshat Zala  > wrote:
>
>> Hello,
>>
>> I am finding it difficult to paginate through all the posts
>>
>> My views.py :
>>
>> @login_required
>> def home_view(request):
>> """Display all the post of friends and own posts on the dashboard"""
>> posts = Post.objects.all().order_by('-date_posted')
>> media: MEDIA_URL
>> # 'post':Post.objects.filter(Q(author=request.user) | 
>> Q(author__from_user=request.user) | 
>> Q(author__to_user=request.user)).order_by('-date_posted'),
>> paginator = Paginator(posts, 2) 
>> page_number = request.GET.get('page')
>> page_obj = paginator.get_page(page_number)
>> return render(request, 'post/home.html',{'page_obj': page_obj})
>>
>>
>> and in template post/home.html:
>>
>> {% if is_paginated %}
>> {% if page_obj.has_previous %}
>> First
>> arrow_left
>> 
>> {% endif %}
>> {% for num in page_obj.paginator.page_range %}
>> {% if page_obj.number == num %}
>> {{ num }}
>> {% elif num > page_obj.number|add:'-4' and num < page_obj.number|add:'4' 
>> %}
>> {{ num }}
>> {% endif %}
>> {% endfor %}
>> {% if page_obj.has_next %}
>> arrow_right
>> Last
>> {% endif %}
>>
>>
>> Thanks
>>
>> Akshat Zala
>>
>> -- 
>> You received this message because you are subscribed to the Google Groups 
>> "Django users" group.
>> To unsubscribe from this group and stop receiving emails from it, send an 
>> email to django...@googlegroups.com .
>> To view this discussion on the web visit 
>> https://groups.google.com/d/msgid/django-users/87c3f0db-3088-448c-b3c7-14450e8c2f5d%40googlegroups.com
>>  
>> 
>> .
>>
>

-- 
You received this message because you are subscribed to the Google Groups 
"Django users" group.
To unsubscribe from this group and stop receiving emails from it, send an email 
to django-users+unsubscr...@googlegroups.com.
To view this discussion on the web visit 
https://groups.google.com/d/msgid/django-users/c775d687-0773-4d09-86be-35e6f2cd55d2%40googlegroups.com.


Re: Django Pagination

2020-05-31 Thread Akshat Zala
Hi,

if I change the template to:

{% if not is_paginated %}
{% if page_obj.has_previous %}
First
arrow_left
{% endif %}
{% for num in page_obj.paginator.page_range %}
{% if page_obj.number == num %}
{{ num }}
{% elif num > page_obj.number|add:'-4' and num < page_obj.number|add:'4' %}
{{ num }}
{% endif %}
{% endfor %}
{% if page_obj.has_next %}
arrow_right
Last
{% endif %}
{% endif %}

It only shows pagination and posts are not seen in template.

On Saturday, 30 May 2020 21:39:52 UTC+5:30, RyuCoder wrote:
>
> Hi akshat,
> What is the difficulty?
> Where have you defined the variable   is_paginated? Is it present in the 
> context?
>
> On Sat, May 30, 2020, 8:53 PM maninder singh Kumar  > wrote:
>
>> Views.py looks fine !
>>
>> regards
>> willy
>>
>>
>> On Sat, May 30, 2020 at 7:22 PM Akshat Zala > > wrote:
>>
>>> Hello,
>>>
>>> I am finding it difficult to paginate through all the posts
>>>
>>> My views.py :
>>>
>>> @login_required
>>> def home_view(request):
>>> """Display all the post of friends and own posts on the dashboard"""
>>> posts = Post.objects.all().order_by('-date_posted')
>>> media: MEDIA_URL
>>> # 'post':Post.objects.filter(Q(author=request.user) | 
>>> Q(author__from_user=request.user) | 
>>> Q(author__to_user=request.user)).order_by('-date_posted'),
>>> paginator = Paginator(posts, 2) 
>>> page_number = request.GET.get('page')
>>> page_obj = paginator.get_page(page_number)
>>> return render(request, 'post/home.html',{'page_obj': page_obj})
>>>
>>>
>>> and in template post/home.html:
>>>
>>> {% if is_paginated %}
>>> {% if page_obj.has_previous %}
>>> First
>>> arrow_left
>>> 
>>> {% endif %}
>>> {% for num in page_obj.paginator.page_range %}
>>> {% if page_obj.number == num %}
>>> {{ num }}
>>> {% elif num > page_obj.number|add:'-4' and num < page_obj.number|add:'4' 
>>> %}
>>> {{ num }}
>>> 
>>> {% endif %}
>>> {% endfor %}
>>> {% if page_obj.has_next %}
>>> arrow_right
>>> Last
>>> {% endif %}
>>>
>>>
>>> Thanks
>>>
>>> Akshat Zala
>>>
>>> -- 
>>> You received this message because you are subscribed to the Google 
>>> Groups "Django users" group.
>>> To unsubscribe from this group and stop receiving emails from it, send 
>>> an email to django...@googlegroups.com .
>>> To view this discussion on the web visit 
>>> https://groups.google.com/d/msgid/django-users/87c3f0db-3088-448c-b3c7-14450e8c2f5d%40googlegroups.com
>>>  
>>> 
>>> .
>>>
>> -- 
>> You received this message because you are subscribed to the Google Groups 
>> "Django users" group.
>> To unsubscribe from this group and stop receiving emails from it, send an 
>> email to django...@googlegroups.com .
>> To view this discussion on the web visit 
>> https://groups.google.com/d/msgid/django-users/CABOHK3QumzEA417%3DMV3dTwRszxmULfHp9y-tADSD56N_sTNQ5g%40mail.gmail.com
>>  
>> 
>> .
>>
>

-- 
You received this message because you are subscribed to the Google Groups 
"Django users" group.
To unsubscribe from this group and stop receiving emails from it, send an email 
to django-users+unsubscr...@googlegroups.com.
To view this discussion on the web visit 
https://groups.google.com/d/msgid/django-users/b91770e1-32cb-4890-bec6-257317696da6%40googlegroups.com.


Re: Django Pagination

2020-05-30 Thread Chetan Ganji
Hi akshat,
What is the difficulty?
Where have you defined the variable   is_paginated? Is it present in the
context?

On Sat, May 30, 2020, 8:53 PM maninder singh Kumar <
maninder.s.ku...@gmail.com> wrote:

> Views.py looks fine !
>
> regards
> willy
>
>
> On Sat, May 30, 2020 at 7:22 PM Akshat Zala  wrote:
>
>> Hello,
>>
>> I am finding it difficult to paginate through all the posts
>>
>> My views.py :
>>
>> @login_required
>> def home_view(request):
>> """Display all the post of friends and own posts on the dashboard"""
>> posts = Post.objects.all().order_by('-date_posted')
>> media: MEDIA_URL
>> # 'post':Post.objects.filter(Q(author=request.user) |
>> Q(author__from_user=request.user) |
>> Q(author__to_user=request.user)).order_by('-date_posted'),
>> paginator = Paginator(posts, 2)
>> page_number = request.GET.get('page')
>> page_obj = paginator.get_page(page_number)
>> return render(request, 'post/home.html',{'page_obj': page_obj})
>>
>>
>> and in template post/home.html:
>>
>> {% if is_paginated %}
>> {% if page_obj.has_previous %}
>> First
>> arrow_left
>> 
>> {% endif %}
>> {% for num in page_obj.paginator.page_range %}
>> {% if page_obj.number == num %}
>> {{ num }}
>> {% elif num > page_obj.number|add:'-4' and num < page_obj.number|add:'4'
>> %}
>> {{ num }}
>> {% endif %}
>> {% endfor %}
>> {% if page_obj.has_next %}
>> arrow_right
>> Last
>> {% endif %}
>>
>>
>> Thanks
>>
>> Akshat Zala
>>
>> --
>> You received this message because you are subscribed to the Google Groups
>> "Django users" group.
>> To unsubscribe from this group and stop receiving emails from it, send an
>> email to django-users+unsubscr...@googlegroups.com.
>> To view this discussion on the web visit
>> https://groups.google.com/d/msgid/django-users/87c3f0db-3088-448c-b3c7-14450e8c2f5d%40googlegroups.com
>> 
>> .
>>
> --
> You received this message because you are subscribed to the Google Groups
> "Django users" group.
> To unsubscribe from this group and stop receiving emails from it, send an
> email to django-users+unsubscr...@googlegroups.com.
> To view this discussion on the web visit
> https://groups.google.com/d/msgid/django-users/CABOHK3QumzEA417%3DMV3dTwRszxmULfHp9y-tADSD56N_sTNQ5g%40mail.gmail.com
> 
> .
>

-- 
You received this message because you are subscribed to the Google Groups 
"Django users" group.
To unsubscribe from this group and stop receiving emails from it, send an email 
to django-users+unsubscr...@googlegroups.com.
To view this discussion on the web visit 
https://groups.google.com/d/msgid/django-users/CAMKMUjveFbK%2BJ3ocK-cTzo%3Dbzt8b%2BSz-dF9C64X4Law-WjkhVA%40mail.gmail.com.


Re: Django Pagination

2020-05-30 Thread maninder singh Kumar
Views.py looks fine !

regards
willy


On Sat, May 30, 2020 at 7:22 PM Akshat Zala  wrote:

> Hello,
>
> I am finding it difficult to paginate through all the posts
>
> My views.py :
>
> @login_required
> def home_view(request):
> """Display all the post of friends and own posts on the dashboard"""
> posts = Post.objects.all().order_by('-date_posted')
> media: MEDIA_URL
> # 'post':Post.objects.filter(Q(author=request.user) |
> Q(author__from_user=request.user) |
> Q(author__to_user=request.user)).order_by('-date_posted'),
> paginator = Paginator(posts, 2)
> page_number = request.GET.get('page')
> page_obj = paginator.get_page(page_number)
> return render(request, 'post/home.html',{'page_obj': page_obj})
>
>
> and in template post/home.html:
>
> {% if is_paginated %}
> {% if page_obj.has_previous %}
> First
> arrow_left
> 
> {% endif %}
> {% for num in page_obj.paginator.page_range %}
> {% if page_obj.number == num %}
> {{ num }}
> {% elif num > page_obj.number|add:'-4' and num < page_obj.number|add:'4'
> %}
> {{ num }}
> {% endif %}
> {% endfor %}
> {% if page_obj.has_next %}
> arrow_right
> Last
> {% endif %}
>
>
> Thanks
>
> Akshat Zala
>
> --
> You received this message because you are subscribed to the Google Groups
> "Django users" group.
> To unsubscribe from this group and stop receiving emails from it, send an
> email to django-users+unsubscr...@googlegroups.com.
> To view this discussion on the web visit
> https://groups.google.com/d/msgid/django-users/87c3f0db-3088-448c-b3c7-14450e8c2f5d%40googlegroups.com
> 
> .
>

-- 
You received this message because you are subscribed to the Google Groups 
"Django users" group.
To unsubscribe from this group and stop receiving emails from it, send an email 
to django-users+unsubscr...@googlegroups.com.
To view this discussion on the web visit 
https://groups.google.com/d/msgid/django-users/CABOHK3QumzEA417%3DMV3dTwRszxmULfHp9y-tADSD56N_sTNQ5g%40mail.gmail.com.


Re: Django Pagination

2020-05-30 Thread Akshat Zala



On Saturday, 30 May 2020 19:20:47 UTC+5:30, Akshat Zala wrote:
>
> Hello,
>
> I am finding it difficult to paginate through all the posts
>
> My views.py :
>
> @login_required
> def home_view(request):
> """Display all the post of friends and own posts on the dashboard"""
> posts = Post.objects.all().order_by('-date_posted')
> media: MEDIA_URL
> # 'post':Post.objects.filter(Q(author=request.user) | 
> Q(author__from_user=request.user) | 
> Q(author__to_user=request.user)).order_by('-date_posted'),
> paginator = Paginator(posts, 2) 
> page_number = request.GET.get('page')
> page_obj = paginator.get_page(page_number)
> return render(request, 'post/home.html',{'page_obj': page_obj})
>
>
> and in template post/home.html:
>
> {% if is_paginated %}
> {% if page_obj.has_previous %}
> First
> arrow_left
> 
> {% endif %}
> {% for num in page_obj.paginator.page_range %}
> {% if page_obj.number == num %}
> {{ num }}
> {% elif num > page_obj.number|add:'-4' and num < page_obj.number|add:'4' 
> %}
> {{ num }}
> {% endif %}
> {% endfor %}
> {% if page_obj.has_next %}
> arrow_right
> Last
> {% endif %}
> {% endif %}
>
> Thanks
>
> Akshat Zala
>
>

-- 
You received this message because you are subscribed to the Google Groups 
"Django users" group.
To unsubscribe from this group and stop receiving emails from it, send an email 
to django-users+unsubscr...@googlegroups.com.
To view this discussion on the web visit 
https://groups.google.com/d/msgid/django-users/97ffaebc-500d-4ae7-a483-bf3f785dee28%40googlegroups.com.


Re: django pagination

2016-01-26 Thread Xristos Xristoou
i find solutio 
using https://docs.djangoproject.com/en/1.9/topics/pagination/ thnX

Τη Τρίτη, 26 Ιανουαρίου 2016 - 3:10:06 μ.μ. UTC+2, ο χρήστης pa xapy έγραψε:
>
> you want to paginate both querysets at the same page? 
> i believe it's a pretty strange idea and if so, you should think how to 
> refactor it
> if you want only paginate posts, i'll recommend you to use 
> django-pagination app of some sort, it's can be used in template
>
> On Monday, January 25, 2016 at 5:16:31 PM UTC+3, Xristos Xristoou wrote:
>>
>> i want to using Paginator in my main page for my post list. i see docs 
>> and examples for that but i thing my problem is a specific, because on my 
>> view i have two Querys not one.
>>
>>
>> def index(request):
>> return render_to_response("blog/posts_list.html", {
>> 'categories': Category.objects.all(),
>> 'posts': 
>> Posts.objects.filter(publisheddate__lte=timezone.now()).order_by('-publisheddate')
>> })
>>
>>
>> any idea how to use Paginator on my view ?
>>
>>

-- 
You received this message because you are subscribed to the Google Groups 
"Django users" group.
To unsubscribe from this group and stop receiving emails from it, send an email 
to django-users+unsubscr...@googlegroups.com.
To post to this group, send email to django-users@googlegroups.com.
Visit this group at https://groups.google.com/group/django-users.
To view this discussion on the web visit 
https://groups.google.com/d/msgid/django-users/58103c46-0740-48c8-8340-0a957c60c4da%40googlegroups.com.
For more options, visit https://groups.google.com/d/optout.


Re: django pagination

2016-01-26 Thread Xristos Xristoou
i foolow the steps but i have again error my new view :

def index(request):
try:
page = request.GET.get('page', 1),
except PageNotAnInteger:
page = 1,
objects = ['john', 'edward', 'josh', 'frank']
p = Paginator(objects,request=request)
people = p.page(page)
return render_to_response("blog/movies_list.html", {
'ranking' : Movies.objects.all().order_by('-rating')[:3],
'likes': Movies.objects.all().order_by('-like')[:3],
'categories': Category.objects.all(),
'people':people,
'posts': 
Movies.objects.filter(publisheddate__lte=timezone.now()).order_by('-publisheddate')
})


first i dont understand how is the objects

the show error in the line :p = Paginator(objects,request=request) any idea ?

-- 
You received this message because you are subscribed to the Google Groups 
"Django users" group.
To unsubscribe from this group and stop receiving emails from it, send an email 
to django-users+unsubscr...@googlegroups.com.
To post to this group, send email to django-users@googlegroups.com.
Visit this group at https://groups.google.com/group/django-users.
To view this discussion on the web visit 
https://groups.google.com/d/msgid/django-users/b914061b-bf4a-4a36-a3df-ca97a5ed1473%40googlegroups.com.
For more options, visit https://groups.google.com/d/optout.


Re: django pagination

2016-01-26 Thread Xristos Xristoou
that method is Confusing,i try to understand,i create new view or i work 
with current?i not understand it the using 'people' and object on they view

Τη Δευτέρα, 25 Ιανουαρίου 2016 - 4:16:31 μ.μ. UTC+2, ο χρήστης Xristos 
Xristoou έγραψε:
>
> i want to using Paginator in my main page for my post list. i see docs and 
> examples for that but i thing my problem is a specific, because on my view 
> i have two Querys not one.
>
>
> def index(request):
> return render_to_response("blog/posts_list.html", {
> 'categories': Category.objects.all(),
> 'posts': 
> Posts.objects.filter(publisheddate__lte=timezone.now()).order_by('-publisheddate')
> })
>
>
> any idea how to use Paginator on my view ?
>
>

-- 
You received this message because you are subscribed to the Google Groups 
"Django users" group.
To unsubscribe from this group and stop receiving emails from it, send an email 
to django-users+unsubscr...@googlegroups.com.
To post to this group, send email to django-users@googlegroups.com.
Visit this group at https://groups.google.com/group/django-users.
To view this discussion on the web visit 
https://groups.google.com/d/msgid/django-users/e4b4344d-5e96-47c7-aff1-74e81b7eb374%40googlegroups.com.
For more options, visit https://groups.google.com/d/optout.


Re: django pagination

2016-01-26 Thread pa xapy
are you using python 3?
that's actually what i talking about - it's too old
try another one, like 
this https://github.com/jamespacileo/django-pure-pagination - follow 
the instructions and i hope you'll be fine

On Tuesday, January 26, 2016 at 5:09:29 PM UTC+3, Xristos Xristoou wrote:
>
> i follow the simpe steps but i take error invalid syntax 
> (pagination_tags.py, line 225)
>
> Τη Δευτέρα, 25 Ιανουαρίου 2016 - 4:16:31 μ.μ. UTC+2, ο χρήστης Xristos 
> Xristoou έγραψε:
>>
>> i want to using Paginator in my main page for my post list. i see docs 
>> and examples for that but i thing my problem is a specific, because on my 
>> view i have two Querys not one.
>>
>>  
>>
> def index(request):
>> return render_to_response("blog/posts_list.html", {
>> 'categories': Category.objects.all(),
>> 'posts': 
>> Posts.objects.filter(publisheddate__lte=timezone.now()).order_by('-publisheddate')
>> })
>>
>>
>> any idea how to use Paginator on my view ?
>>
>>

-- 
You received this message because you are subscribed to the Google Groups 
"Django users" group.
To unsubscribe from this group and stop receiving emails from it, send an email 
to django-users+unsubscr...@googlegroups.com.
To post to this group, send email to django-users@googlegroups.com.
Visit this group at https://groups.google.com/group/django-users.
To view this discussion on the web visit 
https://groups.google.com/d/msgid/django-users/6f57db3c-68e5-40f2-b35a-22d7e43b8355%40googlegroups.com.
For more options, visit https://groups.google.com/d/optout.


Re: django pagination

2016-01-26 Thread Xristos Xristoou
i follow the simpe steps but i take error invalid syntax 
(pagination_tags.py, line 225)

Τη Δευτέρα, 25 Ιανουαρίου 2016 - 4:16:31 μ.μ. UTC+2, ο χρήστης Xristos 
Xristoou έγραψε:
>
> i want to using Paginator in my main page for my post list. i see docs and 
> examples for that but i thing my problem is a specific, because on my view 
> i have two Querys not one.
>
>
> def index(request):
> return render_to_response("blog/posts_list.html", {
> 'categories': Category.objects.all(),
> 'posts': 
> Posts.objects.filter(publisheddate__lte=timezone.now()).order_by('-publisheddate')
> })
>
>
> any idea how to use Paginator on my view ?
>
>

-- 
You received this message because you are subscribed to the Google Groups 
"Django users" group.
To unsubscribe from this group and stop receiving emails from it, send an email 
to django-users+unsubscr...@googlegroups.com.
To post to this group, send email to django-users@googlegroups.com.
Visit this group at https://groups.google.com/group/django-users.
To view this discussion on the web visit 
https://groups.google.com/d/msgid/django-users/e77feb8e-adfd-4468-ab84-80a5d9523c5f%40googlegroups.com.
For more options, visit https://groups.google.com/d/optout.


Re: django pagination

2016-01-26 Thread Xristos Xristoou
thnx you i try to use that now

Τη Δευτέρα, 25 Ιανουαρίου 2016 - 4:16:31 μ.μ. UTC+2, ο χρήστης Xristos 
Xristoou έγραψε:
>
> i want to using Paginator in my main page for my post list. i see docs and 
> examples for that but i thing my problem is a specific, because on my view 
> i have two Querys not one.
>
>
> def index(request):
> return render_to_response("blog/posts_list.html", {
> 'categories': Category.objects.all(),
> 'posts': 
> Posts.objects.filter(publisheddate__lte=timezone.now()).order_by('-publisheddate')
> })
>
>
> any idea how to use Paginator on my view ?
>
>

-- 
You received this message because you are subscribed to the Google Groups 
"Django users" group.
To unsubscribe from this group and stop receiving emails from it, send an email 
to django-users+unsubscr...@googlegroups.com.
To post to this group, send email to django-users@googlegroups.com.
Visit this group at https://groups.google.com/group/django-users.
To view this discussion on the web visit 
https://groups.google.com/d/msgid/django-users/975e3703-a73a-4057-aaf4-341c7ae724d4%40googlegroups.com.
For more options, visit https://groups.google.com/d/optout.


Re: django pagination

2016-01-26 Thread pa xapy
are you familiar with the pip utility?
if not, i highly recommend to read about 
it https://pip.pypa.io/en/stable/quickstart/
if yes, you should know that you can install any application with pip 
install package_name
and how set it up with django - it's better if you read in instructions for 
package you choose

but i'm afraid that this particular app is too old and you can experience 
some troubles with it
anyways, you can try: pip install django-pagination

On Tuesday, January 26, 2016 at 4:44:05 PM UTC+3, Xristos Xristoou wrote:
>
> one more question how to install this ?autopagination ?i dont see anything
>
> Τη Δευτέρα, 25 Ιανουαρίου 2016 - 4:16:31 μ.μ. UTC+2, ο χρήστης Xristos 
> Xristoou έγραψε:
>>
>> i want to using Paginator in my main page for my post list. i see docs 
>> and examples for that but i thing my problem is a specific, because on my 
>> view i have two Querys not one.
>>
>>
>> def index(request):
>> return render_to_response("blog/posts_list.html", {
>> 'categories': Category.objects.all(),
>> 'posts': 
>> Posts.objects.filter(publisheddate__lte=timezone.now()).order_by('-publisheddate')
>> })
>>
>>
>> any idea how to use Paginator on my view ?
>>
>>

-- 
You received this message because you are subscribed to the Google Groups 
"Django users" group.
To unsubscribe from this group and stop receiving emails from it, send an email 
to django-users+unsubscr...@googlegroups.com.
To post to this group, send email to django-users@googlegroups.com.
Visit this group at https://groups.google.com/group/django-users.
To view this discussion on the web visit 
https://groups.google.com/d/msgid/django-users/9a491e58-4f39-4ad0-b502-c1a52579855c%40googlegroups.com.
For more options, visit https://groups.google.com/d/optout.


Re: django pagination

2016-01-26 Thread Xristos Xristoou
one more question how to install this ?autopagination ?i dont see anything

Τη Δευτέρα, 25 Ιανουαρίου 2016 - 4:16:31 μ.μ. UTC+2, ο χρήστης Xristos 
Xristoou έγραψε:
>
> i want to using Paginator in my main page for my post list. i see docs and 
> examples for that but i thing my problem is a specific, because on my view 
> i have two Querys not one.
>
>
> def index(request):
> return render_to_response("blog/posts_list.html", {
> 'categories': Category.objects.all(),
> 'posts': 
> Posts.objects.filter(publisheddate__lte=timezone.now()).order_by('-publisheddate')
> })
>
>
> any idea how to use Paginator on my view ?
>
>

-- 
You received this message because you are subscribed to the Google Groups 
"Django users" group.
To unsubscribe from this group and stop receiving emails from it, send an email 
to django-users+unsubscr...@googlegroups.com.
To post to this group, send email to django-users@googlegroups.com.
Visit this group at https://groups.google.com/group/django-users.
To view this discussion on the web visit 
https://groups.google.com/d/msgid/django-users/20c91b88-4893-4bb1-82a0-c14ddf0b0050%40googlegroups.com.
For more options, visit https://groups.google.com/d/optout.


Re: django pagination

2016-01-26 Thread pa xapy
you can read the usage doc i sent linked, but yes - you don't need to do 
anything with you queryset in view only pass it to template

On Tuesday, January 26, 2016 at 4:39:17 PM UTC+3, Xristos Xristoou wrote:
>
> if i use {autopagination} i dont need quyre on my view ?
>
> Τη Δευτέρα, 25 Ιανουαρίου 2016 - 4:16:31 μ.μ. UTC+2, ο χρήστης Xristos 
> Xristoou έγραψε:
>>
>> i want to using Paginator in my main page for my post list. i see docs 
>> and examples for that but i thing my problem is a specific, because on my 
>> view i have two Querys not one.
>>
>>
>> def index(request):
>> return render_to_response("blog/posts_list.html", {
>> 'categories': Category.objects.all(),
>> 'posts': 
>> Posts.objects.filter(publisheddate__lte=timezone.now()).order_by('-publisheddate')
>> })
>>
>>
>> any idea how to use Paginator on my view ?
>>
>>

-- 
You received this message because you are subscribed to the Google Groups 
"Django users" group.
To unsubscribe from this group and stop receiving emails from it, send an email 
to django-users+unsubscr...@googlegroups.com.
To post to this group, send email to django-users@googlegroups.com.
Visit this group at https://groups.google.com/group/django-users.
To view this discussion on the web visit 
https://groups.google.com/d/msgid/django-users/82411c31-5085-4b0f-955c-232f36ff7288%40googlegroups.com.
For more options, visit https://groups.google.com/d/optout.


Re: django pagination

2016-01-26 Thread Xristos Xristoou
if i use {autopagination} i dont need quyre on my view ?

Τη Δευτέρα, 25 Ιανουαρίου 2016 - 4:16:31 μ.μ. UTC+2, ο χρήστης Xristos 
Xristoou έγραψε:
>
> i want to using Paginator in my main page for my post list. i see docs and 
> examples for that but i thing my problem is a specific, because on my view 
> i have two Querys not one.
>
>
> def index(request):
> return render_to_response("blog/posts_list.html", {
> 'categories': Category.objects.all(),
> 'posts': 
> Posts.objects.filter(publisheddate__lte=timezone.now()).order_by('-publisheddate')
> })
>
>
> any idea how to use Paginator on my view ?
>
>

-- 
You received this message because you are subscribed to the Google Groups 
"Django users" group.
To unsubscribe from this group and stop receiving emails from it, send an email 
to django-users+unsubscr...@googlegroups.com.
To post to this group, send email to django-users@googlegroups.com.
Visit this group at https://groups.google.com/group/django-users.
To view this discussion on the web visit 
https://groups.google.com/d/msgid/django-users/6ec5fa3d-9f45-4a0a-8ee6-3ef44893a24d%40googlegroups.com.
For more options, visit https://groups.google.com/d/optout.


Re: django pagination

2016-01-26 Thread pa xapy
if you'll decide to use some app for pagination, you can do it in template, 
like 
so https://github.com/ericflo/django-pagination/blob/master/docs/usage.txt 
({% autopaginate posts 10 %})
or you can choose one of 
these https://www.djangopackages.com/grids/g/pagination/
there is no actual need to do it in view
but still, if you want to only paginate posts, I can't see a problem at all

On Tuesday, January 26, 2016 at 4:27:58 PM UTC+3, Xristos Xristoou wrote:
>
> can you show me one examples with my view ?
>
> Τη Δευτέρα, 25 Ιανουαρίου 2016 - 4:16:31 μ.μ. UTC+2, ο χρήστης Xristos 
> Xristoou έγραψε:
>>
>> i want to using Paginator in my main page for my post list. i see docs 
>> and examples for that but i thing my problem is a specific, because on my 
>> view i have two Querys not one.
>>
>>
>> def index(request):
>> return render_to_response("blog/posts_list.html", {
>> 'categories': Category.objects.all(),
>> 'posts': 
>> Posts.objects.filter(publisheddate__lte=timezone.now()).order_by('-publisheddate')
>> })
>>
>>
>> any idea how to use Paginator on my view ?
>>
>>

-- 
You received this message because you are subscribed to the Google Groups 
"Django users" group.
To unsubscribe from this group and stop receiving emails from it, send an email 
to django-users+unsubscr...@googlegroups.com.
To post to this group, send email to django-users@googlegroups.com.
Visit this group at https://groups.google.com/group/django-users.
To view this discussion on the web visit 
https://groups.google.com/d/msgid/django-users/5d3687ed-64f8-43ce-a20c-43c45e957633%40googlegroups.com.
For more options, visit https://groups.google.com/d/optout.


Re: django pagination

2016-01-26 Thread Xristos Xristoou
can you show me one examples with my view ?

Τη Δευτέρα, 25 Ιανουαρίου 2016 - 4:16:31 μ.μ. UTC+2, ο χρήστης Xristos 
Xristoou έγραψε:
>
> i want to using Paginator in my main page for my post list. i see docs and 
> examples for that but i thing my problem is a specific, because on my view 
> i have two Querys not one.
>
>
> def index(request):
> return render_to_response("blog/posts_list.html", {
> 'categories': Category.objects.all(),
> 'posts': 
> Posts.objects.filter(publisheddate__lte=timezone.now()).order_by('-publisheddate')
> })
>
>
> any idea how to use Paginator on my view ?
>
>

-- 
You received this message because you are subscribed to the Google Groups 
"Django users" group.
To unsubscribe from this group and stop receiving emails from it, send an email 
to django-users+unsubscr...@googlegroups.com.
To post to this group, send email to django-users@googlegroups.com.
Visit this group at https://groups.google.com/group/django-users.
To view this discussion on the web visit 
https://groups.google.com/d/msgid/django-users/12b31dc3-77ca-4e32-b340-8d0019b9f580%40googlegroups.com.
For more options, visit https://groups.google.com/d/optout.


Re: django pagination

2016-01-26 Thread pa xapy
you want to paginate both querysets at the same page? 
i believe it's a pretty strange idea and if so, you should think how to 
refactor it
if you want only paginate posts, i'll recommend you to use 
django-pagination app of some sort, it's can be used in template

On Monday, January 25, 2016 at 5:16:31 PM UTC+3, Xristos Xristoou wrote:
>
> i want to using Paginator in my main page for my post list. i see docs and 
> examples for that but i thing my problem is a specific, because on my view 
> i have two Querys not one.
>
>
> def index(request):
> return render_to_response("blog/posts_list.html", {
> 'categories': Category.objects.all(),
> 'posts': 
> Posts.objects.filter(publisheddate__lte=timezone.now()).order_by('-publisheddate')
> })
>
>
> any idea how to use Paginator on my view ?
>
>

-- 
You received this message because you are subscribed to the Google Groups 
"Django users" group.
To unsubscribe from this group and stop receiving emails from it, send an email 
to django-users+unsubscr...@googlegroups.com.
To post to this group, send email to django-users@googlegroups.com.
Visit this group at https://groups.google.com/group/django-users.
To view this discussion on the web visit 
https://groups.google.com/d/msgid/django-users/6ef8c4c5-4354-4c97-b0a0-9c28f49ab773%40googlegroups.com.
For more options, visit https://groups.google.com/d/optout.


Re: Django Pagination

2013-10-03 Thread Hélio Miranda
Thanks for the help guys, I managed to solve, so I did:

* queryset = Player.objects.filter(name=namepost)*
*paginator = Paginator(queryset, 2)*
*
*
*try: *
* page = int(request.POST.get('page','1')) *
*except ValueError: *
* page = 1 *
*try: *
*results = paginator.page(page) *
*except (EmptyPage, InvalidPage): *
*results = paginator.page(paginator.num_pages) *
*return HttpResponse(json.dumps([item.get_json() for item in 
results.object_list]) , content_type='application/json')*

-- 
You received this message because you are subscribed to the Google Groups 
"Django users" group.
To unsubscribe from this group and stop receiving emails from it, send an email 
to django-users+unsubscr...@googlegroups.com.
To post to this group, send email to django-users@googlegroups.com.
Visit this group at http://groups.google.com/group/django-users.
To view this discussion on the web visit 
https://groups.google.com/d/msgid/django-users/8b0e5b6c-6337-4ea5-8020-535377657b15%40googlegroups.com.
For more options, visit https://groups.google.com/groups/opt_out.


Re: Django Pagination

2013-10-03 Thread Hélio Miranda
thus still giving the same error

-- 
You received this message because you are subscribed to the Google Groups 
"Django users" group.
To unsubscribe from this group and stop receiving emails from it, send an email 
to django-users+unsubscr...@googlegroups.com.
To post to this group, send email to django-users@googlegroups.com.
Visit this group at http://groups.google.com/group/django-users.
To view this discussion on the web visit 
https://groups.google.com/d/msgid/django-users/0a0a64c2-c573-4803-a192-fee936e0d65b%40googlegroups.com.
For more options, visit https://groups.google.com/groups/opt_out.


Re: Django Pagination

2013-10-03 Thread Roberto López López
On 10/03/2013 04:13 PM, Roberto López López wrote:
> *return HttpResponse(json.dumps([players]) ,
> content_type='application/json')*
better without the square brackets

*return HttpResponse(json.dumps(players) ,
content_type='application/json')*

-- 

Roberto López López
System Developer
Parallab, Uni Computing
+47 55584091

-- 
You received this message because you are subscribed to the Google Groups 
"Django users" group.
To unsubscribe from this group and stop receiving emails from it, send an email 
to django-users+unsubscr...@googlegroups.com.
To post to this group, send email to django-users@googlegroups.com.
Visit this group at http://groups.google.com/group/django-users.
To view this discussion on the web visit 
https://groups.google.com/d/msgid/django-users/524D7F41.7070003%40uni.no.
For more options, visit https://groups.google.com/groups/opt_out.


Re: Django Pagination

2013-10-03 Thread Hélio Miranda
doing so:
*queryset = Player.objects.filter(name=namepost)*
*paginator = Paginator(queryset, 2)*
*
*
*page = request.GET.get('page')*
*try:*
*players = paginator.page(page)*
*except PageNotAnInteger:*
*players = paginator.page(1)*
*except EmptyPage:*
*players = paginator.page(paginator.num_pages)*
*return HttpResponse(json.dumps(players) , 
content_type='application/json')*

Gives the following error:

 is not JSON serializable


Testing like this:*queryset = Player.objects.filter(name=namepost)
paginator = Paginator(queryset, 2)
  return HttpResponse(json.dumps([item.get_json() for item in 
paginator.page(1)]) , content_type='application/json')*

works, but I have to put the page number of manually

-- 
You received this message because you are subscribed to the Google Groups 
"Django users" group.
To unsubscribe from this group and stop receiving emails from it, send an email 
to django-users+unsubscr...@googlegroups.com.
To post to this group, send email to django-users@googlegroups.com.
Visit this group at http://groups.google.com/group/django-users.
To view this discussion on the web visit 
https://groups.google.com/d/msgid/django-users/7c2ad980-05f2-408e-8049-96c5900fb4f9%40googlegroups.com.
For more options, visit https://groups.google.com/groups/opt_out.


Re: Django Pagination

2013-10-03 Thread Roberto López López
Try this (I have not tried the code myself, but I think that it should
work):

*queryset = Player.objects.filter(name=namepost)*
*paginator = Paginator(queryset, 2)
page = request.GET.get('page')
try:
players = paginator.page(page)
except PageNotAnInteger:
players = paginator.page(1)
except EmptyPage:
players = paginator.page(paginator.num_pages)
*
*return HttpResponse(json.dumps([players]) ,
content_type='application/json')*



On 10/03/2013 04:07 PM, Hélio Miranda wrote:
> Already got it, I did so:
> *queryset = Player.objects.filter(name=namepost)*
> *paginator = Paginator(queryset, 2)*
> *return HttpResponse(json.dumps([item.get_json() for item in
> paginator.object_list]) , content_type='application/json')*
>
> But I return all the records ... I should not return only 2?
> -- 
> You received this message because you are subscribed to the Google
> Groups "Django users" group.
> To unsubscribe from this group and stop receiving emails from it, send
> an email to django-users+unsubscr...@googlegroups.com.
> To post to this group, send email to django-users@googlegroups.com.
> Visit this group at http://groups.google.com/group/django-users.
> To view this discussion on the web visit
> https://groups.google.com/d/msgid/django-users/e7e37ad2-281c-41f4-a0b9-b333294fe1b8%40googlegroups.com.
> For more options, visit https://groups.google.com/groups/opt_out.


-- 

Roberto López López
System Developer
Parallab, Uni Computing
+47 55584091

-- 
You received this message because you are subscribed to the Google Groups 
"Django users" group.
To unsubscribe from this group and stop receiving emails from it, send an email 
to django-users+unsubscr...@googlegroups.com.
To post to this group, send email to django-users@googlegroups.com.
Visit this group at http://groups.google.com/group/django-users.
To view this discussion on the web visit 
https://groups.google.com/d/msgid/django-users/524D7B79.4090400%40uni.no.
For more options, visit https://groups.google.com/groups/opt_out.


Re: Django Pagination

2013-10-03 Thread Roberto López López
Better to say:

*queryset = Player.objects.filter(name=namepost)*
*paginator = Paginator(queryset, 2)
page = request.GET.get('page')
try:
players = paginator.page(page)
except PageNotAnInteger:
players = paginator.page(1)
except EmptyPage:
players = paginator.page(paginator.num_pages)
*
*return HttpResponse(json.dumps(players) ,
content_type='application/json')*


On 10/03/2013 04:07 PM, Hélio Miranda wrote:
> Already got it, I did so:
> *queryset = Player.objects.filter(name=namepost)*
> *paginator = Paginator(queryset, 2)*
> *return HttpResponse(json.dumps([item.get_json() for item in
> paginator.object_list]) , content_type='application/json')*
>
> But I return all the records ... I should not return only 2?
> -- 
> You received this message because you are subscribed to the Google
> Groups "Django users" group.
> To unsubscribe from this group and stop receiving emails from it, send
> an email to django-users+unsubscr...@googlegroups.com.
> To post to this group, send email to django-users@googlegroups.com.
> Visit this group at http://groups.google.com/group/django-users.
> To view this discussion on the web visit
> https://groups.google.com/d/msgid/django-users/e7e37ad2-281c-41f4-a0b9-b333294fe1b8%40googlegroups.com.
> For more options, visit https://groups.google.com/groups/opt_out.


-- 

Roberto López López
System Developer
Parallab, Uni Computing
+47 55584091

-- 
You received this message because you are subscribed to the Google Groups 
"Django users" group.
To unsubscribe from this group and stop receiving emails from it, send an email 
to django-users+unsubscr...@googlegroups.com.
To post to this group, send email to django-users@googlegroups.com.
Visit this group at http://groups.google.com/group/django-users.
To view this discussion on the web visit 
https://groups.google.com/d/msgid/django-users/524D7BB6.1050502%40uni.no.
For more options, visit https://groups.google.com/groups/opt_out.


Re: Django Pagination

2013-10-03 Thread Hélio Miranda
Already got it, I did so:
*queryset = Player.objects.filter(name=namepost)*
*paginator = Paginator(queryset, 2)*
*return HttpResponse(json.dumps([item.get_json() for item in 
paginator.object_list]) , content_type='application/json')*

But I return all the records ... I should not return only 2?

-- 
You received this message because you are subscribed to the Google Groups 
"Django users" group.
To unsubscribe from this group and stop receiving emails from it, send an email 
to django-users+unsubscr...@googlegroups.com.
To post to this group, send email to django-users@googlegroups.com.
Visit this group at http://groups.google.com/group/django-users.
To view this discussion on the web visit 
https://groups.google.com/d/msgid/django-users/e7e37ad2-281c-41f4-a0b9-b333294fe1b8%40googlegroups.com.
For more options, visit https://groups.google.com/groups/opt_out.


Re: Django Pagination

2013-10-03 Thread Hélio Miranda
Already got it, I did so:
*queryset = Player.objects.filter(name=namepost)*
*paginator = Paginator(queryset, 1)*
*return HttpResponse(json.dumps([item.get_json() for item in 
paginator.object_list]) , content_type='application/json')*

But I return all the records ... I should not return only 2?

-- 
You received this message because you are subscribed to the Google Groups 
"Django users" group.
To unsubscribe from this group and stop receiving emails from it, send an email 
to django-users+unsubscr...@googlegroups.com.
To post to this group, send email to django-users@googlegroups.com.
Visit this group at http://groups.google.com/group/django-users.
To view this discussion on the web visit 
https://groups.google.com/d/msgid/django-users/883c9f30-980a-4d9b-b116-5b5b9da04b5d%40googlegroups.com.
For more options, visit https://groups.google.com/groups/opt_out.


Re: Django Pagination

2013-10-03 Thread Hélio Miranda
I'm doing this:
*queryset = Player.objects.filter(name=namepost)*
*paginator = Paginator(queryset, 20)*
*return json.dumps([item.get_json() for item in paginator.object_list])*

And my Document is thus:
http://plnkr.co/edit/FHH2hZh26OiLMKTk2ToO

But it gives me the following error:

'str' object has no attribute 'status_code'

-- 
You received this message because you are subscribed to the Google Groups 
"Django users" group.
To unsubscribe from this group and stop receiving emails from it, send an email 
to django-users+unsubscr...@googlegroups.com.
To post to this group, send email to django-users@googlegroups.com.
Visit this group at http://groups.google.com/group/django-users.
To view this discussion on the web visit 
https://groups.google.com/d/msgid/django-users/29b801fe-644c-42b4-85aa-733de74c341a%40googlegroups.com.
For more options, visit https://groups.google.com/groups/opt_out.


Re: Django Pagination

2013-10-03 Thread Tom Christie
Hi Hélio,

It looks like you're applying pagination to the rendered JSON string itself.
You want to be paginating the queryset itself.

queryset = Player.objects.filter(name=namepost)
paginator = Paginator(queryset, 20)
return json.dumps([item.to_dict() for item in paginator.object_list])

Hope that helps.

On Thursday, 3 October 2013 14:34:18 UTC+1, Hélio Miranda wrote:
>
> Hi guys.
>
> I'm here with a problem that does not quite know how to solve.
> I have this query:
> result = json.dumps([a.get_json() for a in 
> Player.objects.filter(name=namepost)])
>
> But now I want to return the result with paging, and do not really know 
> how to do ... I've been seeing in the documentation to use the Paginator.
>
> But for example when I do this
> p = Paginator(result, 2)
> print p.count
>
> Gives 1609 ... and the result of the query is 3 records.
>
> Someone can help me?
>

-- 
You received this message because you are subscribed to the Google Groups 
"Django users" group.
To unsubscribe from this group and stop receiving emails from it, send an email 
to django-users+unsubscr...@googlegroups.com.
To post to this group, send email to django-users@googlegroups.com.
Visit this group at http://groups.google.com/group/django-users.
To view this discussion on the web visit 
https://groups.google.com/d/msgid/django-users/ee66f864-30c7-450d-806a-763f12313c89%40googlegroups.com.
For more options, visit https://groups.google.com/groups/opt_out.


Re: Django Pagination Not Working!

2012-05-08 Thread Tom Evans
On Sun, May 6, 2012 at 10:56 PM, coded kid  wrote:
> I'm trying to paginate a page in order to display five statuses per
> page. After inputting these codes, it fails to paginate. Below are the
> codes for pagination and updating of status in my django app.
>
>
> Views:
>
>  def qask(request):
>          extra_data_context={}
>             #if there's nothing in the field do nothing.
>          if request. method=="POST":
>              form =AskForm(request.POST)
>              if form.is_valid():
>                  data=form.cleaned_data
>                  newask=Ask(
>                     user= request.user,
>                     status=data['status'],
>                     pub_date=datetime.datetime.now())
>                 newask.save()
>              extra_data_context.update({'AskForm':form})
>        else:
>            form = AskForm()
>            extra_data_context.update({'AskForm':form})
>
> extra_data_context.update({'Asks':Ask.objects.filter(user=request.user)})

So here you specify 'Asks' as all Ask objects associated with the current user.

>
>       plan=Ask.objects.all()
>       paginator=Paginator(plan, 5)
>
>       try:
>           page=int(request.GET.get('page','1'))
>       except ValueError:
>           page=1
>
>       try:
>          fp=paginator.page(page)
>      except (EmptyPage, InvalidPage):
>          fp=paginator.page(paginator.num_pages)

Here you paginate all Ask objects, and don't do anything with pagination object.


>      return render_to_response
> ('quik_ask.html',extra_data_context,context_instance=RequestContext(request))
>
> Template:
>  {% block content %}
>
>
>
>          {% for Ask in Asks %}
>       
>         {{Ask.user}}  
>         {{Ask.status}}
>           {{Ask.state}} | {{Ask.pub_date|timesince }} ago 
>
>          
>        {% endfor %}
>
>    
>       
>    {% if Asks.has_previous %}

And here you start using 'Asks' in the template as though it had been
paginated and was not a raw queryset. This is unlikely to work.

When you paginate a queryset, you need to create a paginator object
with that queryset, page the paginator to select an appropriate page,
and then pass the page to the template.

This is covered in mind numbing detail in the Django docs:

https://docs.djangoproject.com/en/1.4/topics/pagination/#using-paginator-in-a-view

Cheers

Tom

-- 
You received this message because you are subscribed to the Google Groups 
"Django users" group.
To post to this group, send email to django-users@googlegroups.com.
To unsubscribe from this group, send email to 
django-users+unsubscr...@googlegroups.com.
For more options, visit this group at 
http://groups.google.com/group/django-users?hl=en.



Re: Django pagination is repeating results

2011-02-24 Thread diogobaeder
Nevermind, it is a SQL Server problem. (I hate SQL Server. There, I
said it.)

I had to first filter manually by the m2m objects, then apply the
pagination to the results.

Thanks!

On Feb 18, 2:53 pm, David De La Harpe Golden
 wrote:
> On 18/02/11 17:38,diogobaederwrote:
>
> > Hi,
> > Any ideas of what might be happening?
>
> Have you set a Meta.ordering on your Model (or applied an .order_by()
> to the QuerySet?)

-- 
You received this message because you are subscribed to the Google Groups 
"Django users" group.
To post to this group, send email to django-users@googlegroups.com.
To unsubscribe from this group, send email to 
django-users+unsubscr...@googlegroups.com.
For more options, visit this group at 
http://groups.google.com/group/django-users?hl=en.



Re: Django pagination is repeating results

2011-02-18 Thread David De La Harpe Golden
On 18/02/11 17:38, diogobaeder wrote:
> Hi,

> Any ideas of what might be happening?
> 

Have you set a Meta.ordering on your Model (or applied an .order_by()
to the QuerySet?)


-- 
You received this message because you are subscribed to the Google Groups 
"Django users" group.
To post to this group, send email to django-users@googlegroups.com.
To unsubscribe from this group, send email to 
django-users+unsubscr...@googlegroups.com.
For more options, visit this group at 
http://groups.google.com/group/django-users?hl=en.



Re: django pagination

2010-08-06 Thread kostia
I don't have time to watch your code, but...

Take a look here http://www.tummy.com/Community/Articles/django-pagination/

I set up this cool pagination in 15 minutes without errors!

-- 
You received this message because you are subscribed to the Google Groups 
"Django users" group.
To post to this group, send email to django-us...@googlegroups.com.
To unsubscribe from this group, send email to 
django-users+unsubscr...@googlegroups.com.
For more options, visit this group at 
http://groups.google.com/group/django-users?hl=en.



Re: "django-pagination" and generic.views.date_based.archive_index()

2009-10-21 Thread tezro

Thanks again. Did it with object_list. Thanks for help :)

On Oct 19, 2:16 pm, Михаил Лукин  wrote:
> Finally, I see only 3 ways:
> 1. copy/paste archive index code and change it's behaviour so it can eat
> num_latest=None
> 2. patch date_based.py in same way as (1)
> 3. use list_detail.object_list
> Since 1-2 are dirty, I would recommend 3rd way. I'll let you know if I could
> suggest something else :)
>
> 2009/10/19 tezro 
>
>
>
>
>
> > Surely I could use the list_detail.object_list, but the use of date
> > based generics though ))
>
> > On Oct 18, 11:45 pm, Михаил Лукин  wrote:
> > > Sorry, didn't look at condition well...:(
>
> > > So, you see the source and you see that there's no way to get all the
> > > records with this view.
> > > Why don't you use list_detail.object_list view? If you need just to order
> > > list by date, you can use ordering on the model level:
> >http://docs.djangoproject.com/en/dev/ref/models/options/#ordering
>
> > > 2009/10/18 tezro 
>
> > > > Would it? If "latest=None" doesn't it mean that there are no entries?
>
> > > > By the way, if I pass None to the condition, it returns False, so
> > > > latest is None.
>
> > > > Or isn't it?
>
> > > > Also the template cannot render it, cause "object of type 'NoneType'
> > > > has no len()".
>
> > > > Anyways, thanks for reply :)
>
> > > > On Oct 18, 11:04 pm, Mihail Lukin  wrote:
> > > > > Look at date_based.py:
>
> > > > >     if date_list and num_latest:
> > > > >         latest = queryset.order_by('-'+date_field)[:num_latest]
> > > > >     else:
> > > > >         latest = None
>
> > > > > So, if you use num_latest=None, you will always get the whole list.
>
> > > > > On Aug 30, 2:47 pm, tezro  wrote:
>
> > > > > > Anyone?
>
> > > > > > On Aug 14, 8:29 am, tezro  wrote:
>
> > > > > > > The question is that
> > > > "django.views.generic.date_based.archive_index()"
> > > > > > > takes an optional argument "num_latest" which is 15 by default.
> > > > > > > Setting it manually to num_latest=10 is way off to
> > correct to
> > > > > > > me. It works. I suppose that it even doesn't retrieve all the
> > tons of
> > > > > > > data from the DB, but what if I have 10 + 1 record :)
>
> > > > > > > What's the right way to use "django-pagination" and the
> > > > "archive_index
> > > > > > > ()" or am I missing something?
>
> > > > > > > Example code.
> > > > > > > ___
>
> > > > > > > def index(request):
> > > > > > >         qs = News.objects.filter(is_published=1)
> > > > > > >         return archive_index(request, qs, 'date',
> > > > num_latest=1)
> > > > > > > ___
>
> > > > > > > Thanks.
>
> > > --
> > > regards,
> > > Mihail
>
> --
> regards,
> Mihail
--~--~-~--~~~---~--~~
You received this message because you are subscribed to the Google Groups 
"Django users" group.
To post to this group, send email to django-users@googlegroups.com
To unsubscribe from this group, send email to 
django-users+unsubscr...@googlegroups.com
For more options, visit this group at 
http://groups.google.com/group/django-users?hl=en
-~--~~~~--~~--~--~---



Re: "django-pagination" and generic.views.date_based.archive_index()

2009-10-19 Thread Михаил Лукин
Finally, I see only 3 ways:
1. copy/paste archive index code and change it's behaviour so it can eat
num_latest=None
2. patch date_based.py in same way as (1)
3. use list_detail.object_list
Since 1-2 are dirty, I would recommend 3rd way. I'll let you know if I could
suggest something else :)

2009/10/19 tezro 

>
> Surely I could use the list_detail.object_list, but the use of date
> based generics though ))
>
>
> On Oct 18, 11:45 pm, Михаил Лукин  wrote:
> > Sorry, didn't look at condition well...:(
> >
> > So, you see the source and you see that there's no way to get all the
> > records with this view.
> > Why don't you use list_detail.object_list view? If you need just to order
> > list by date, you can use ordering on the model level:
> http://docs.djangoproject.com/en/dev/ref/models/options/#ordering
> >
> > 2009/10/18 tezro 
> >
> >
> >
> >
> >
> > > Would it? If "latest=None" doesn't it mean that there are no entries?
> >
> > > By the way, if I pass None to the condition, it returns False, so
> > > latest is None.
> >
> > > Or isn't it?
> >
> > > Also the template cannot render it, cause "object of type 'NoneType'
> > > has no len()".
> >
> > > Anyways, thanks for reply :)
> >
> > > On Oct 18, 11:04 pm, Mihail Lukin  wrote:
> > > > Look at date_based.py:
> >
> > > > if date_list and num_latest:
> > > > latest = queryset.order_by('-'+date_field)[:num_latest]
> > > > else:
> > > > latest = None
> >
> > > > So, if you use num_latest=None, you will always get the whole list.
> >
> > > > On Aug 30, 2:47 pm, tezro  wrote:
> >
> > > > > Anyone?
> >
> > > > > On Aug 14, 8:29 am, tezro  wrote:
> >
> > > > > > The question is that
> > > "django.views.generic.date_based.archive_index()"
> > > > > > takes an optional argument "num_latest" which is 15 by default.
> > > > > > Setting it manually to num_latest=10 is way off to
> correct to
> > > > > > me. It works. I suppose that it even doesn't retrieve all the
> tons of
> > > > > > data from the DB, but what if I have 10 + 1 record :)
> >
> > > > > > What's the right way to use "django-pagination" and the
> > > "archive_index
> > > > > > ()" or am I missing something?
> >
> > > > > > Example code.
> > > > > > ___
> >
> > > > > > def index(request):
> > > > > > qs = News.objects.filter(is_published=1)
> > > > > > return archive_index(request, qs, 'date',
> > > num_latest=1)
> > > > > > ___
> >
> > > > > > Thanks.
> >
> > --
> > regards,
> > Mihail
> >
>


-- 
regards,
Mihail

--~--~-~--~~~---~--~~
You received this message because you are subscribed to the Google Groups 
"Django users" group.
To post to this group, send email to django-users@googlegroups.com
To unsubscribe from this group, send email to 
django-users+unsubscr...@googlegroups.com
For more options, visit this group at 
http://groups.google.com/group/django-users?hl=en
-~--~~~~--~~--~--~---



Re: "django-pagination" and generic.views.date_based.archive_index()

2009-10-19 Thread tezro

Surely I could use the list_detail.object_list, but the use of date
based generics though ))


On Oct 18, 11:45 pm, Михаил Лукин  wrote:
> Sorry, didn't look at condition well...:(
>
> So, you see the source and you see that there's no way to get all the
> records with this view.
> Why don't you use list_detail.object_list view? If you need just to order
> list by date, you can use ordering on the model 
> level:http://docs.djangoproject.com/en/dev/ref/models/options/#ordering
>
> 2009/10/18 tezro 
>
>
>
>
>
> > Would it? If "latest=None" doesn't it mean that there are no entries?
>
> > By the way, if I pass None to the condition, it returns False, so
> > latest is None.
>
> > Or isn't it?
>
> > Also the template cannot render it, cause "object of type 'NoneType'
> > has no len()".
>
> > Anyways, thanks for reply :)
>
> > On Oct 18, 11:04 pm, Mihail Lukin  wrote:
> > > Look at date_based.py:
>
> > >     if date_list and num_latest:
> > >         latest = queryset.order_by('-'+date_field)[:num_latest]
> > >     else:
> > >         latest = None
>
> > > So, if you use num_latest=None, you will always get the whole list.
>
> > > On Aug 30, 2:47 pm, tezro  wrote:
>
> > > > Anyone?
>
> > > > On Aug 14, 8:29 am, tezro  wrote:
>
> > > > > The question is that
> > "django.views.generic.date_based.archive_index()"
> > > > > takes an optional argument "num_latest" which is 15 by default.
> > > > > Setting it manually to num_latest=10 is way off to correct to
> > > > > me. It works. I suppose that it even doesn't retrieve all the tons of
> > > > > data from the DB, but what if I have 10 + 1 record :)
>
> > > > > What's the right way to use "django-pagination" and the
> > "archive_index
> > > > > ()" or am I missing something?
>
> > > > > Example code.
> > > > > ___
>
> > > > > def index(request):
> > > > >         qs = News.objects.filter(is_published=1)
> > > > >         return archive_index(request, qs, 'date',
> > num_latest=1)
> > > > > ___
>
> > > > > Thanks.
>
> --
> regards,
> Mihail
--~--~-~--~~~---~--~~
You received this message because you are subscribed to the Google Groups 
"Django users" group.
To post to this group, send email to django-users@googlegroups.com
To unsubscribe from this group, send email to 
django-users+unsubscr...@googlegroups.com
For more options, visit this group at 
http://groups.google.com/group/django-users?hl=en
-~--~~~~--~~--~--~---



Re: "django-pagination" and generic.views.date_based.archive_index()

2009-10-18 Thread Михаил Лукин
Sorry, didn't look at condition well...:(

So, you see the source and you see that there's no way to get all the
records with this view.
Why don't you use list_detail.object_list view? If you need just to order
list by date, you can use ordering on the model level:
http://docs.djangoproject.com/en/dev/ref/models/options/#ordering

2009/10/18 tezro 

>
> Would it? If "latest=None" doesn't it mean that there are no entries?
>
> By the way, if I pass None to the condition, it returns False, so
> latest is None.
>
> Or isn't it?
>
> Also the template cannot render it, cause "object of type 'NoneType'
> has no len()".
>
> Anyways, thanks for reply :)
>
>
>
> On Oct 18, 11:04 pm, Mihail Lukin  wrote:
> > Look at date_based.py:
> >
> > if date_list and num_latest:
> > latest = queryset.order_by('-'+date_field)[:num_latest]
> > else:
> > latest = None
> >
> > So, if you use num_latest=None, you will always get the whole list.
> >
> > On Aug 30, 2:47 pm, tezro  wrote:
> >
> > > Anyone?
> >
> > > On Aug 14, 8:29 am, tezro  wrote:
> >
> > > > The question is that
> "django.views.generic.date_based.archive_index()"
> > > > takes an optional argument "num_latest" which is 15 by default.
> > > > Setting it manually to num_latest=10 is way off to correct to
> > > > me. It works. I suppose that it even doesn't retrieve all the tons of
> > > > data from the DB, but what if I have 10 + 1 record :)
> >
> > > > What's the right way to use "django-pagination" and the
> "archive_index
> > > > ()" or am I missing something?
> >
> > > > Example code.
> > > > ___
> >
> > > > def index(request):
> > > > qs = News.objects.filter(is_published=1)
> > > > return archive_index(request, qs, 'date',
> num_latest=1)
> > > > ___
> >
> > > > Thanks.
> >
> >
> >
>


-- 
regards,
Mihail

--~--~-~--~~~---~--~~
You received this message because you are subscribed to the Google Groups 
"Django users" group.
To post to this group, send email to django-users@googlegroups.com
To unsubscribe from this group, send email to 
django-users+unsubscr...@googlegroups.com
For more options, visit this group at 
http://groups.google.com/group/django-users?hl=en
-~--~~~~--~~--~--~---



Re: "django-pagination" and generic.views.date_based.archive_index()

2009-10-18 Thread tezro

Would it? If "latest=None" doesn't it mean that there are no entries?

By the way, if I pass None to the condition, it returns False, so
latest is None.

Or isn't it?

Also the template cannot render it, cause "object of type 'NoneType'
has no len()".

Anyways, thanks for reply :)



On Oct 18, 11:04 pm, Mihail Lukin  wrote:
> Look at date_based.py:
>
>     if date_list and num_latest:
>         latest = queryset.order_by('-'+date_field)[:num_latest]
>     else:
>         latest = None
>
> So, if you use num_latest=None, you will always get the whole list.
>
> On Aug 30, 2:47 pm, tezro  wrote:
>
> > Anyone?
>
> > On Aug 14, 8:29 am, tezro  wrote:
>
> > > The question is that "django.views.generic.date_based.archive_index()"
> > > takes an optional argument "num_latest" which is 15 by default.
> > > Setting it manually to num_latest=10 is way off to correct to
> > > me. It works. I suppose that it even doesn't retrieve all the tons of
> > > data from the DB, but what if I have 10 + 1 record :)
>
> > > What's the right way to use "django-pagination" and the "archive_index
> > > ()" or am I missing something?
>
> > > Example code.
> > > ___
>
> > > def index(request):
> > >         qs = News.objects.filter(is_published=1)
> > >         return archive_index(request, qs, 'date', num_latest=1)
> > > ___
>
> > > Thanks.
>
>
--~--~-~--~~~---~--~~
You received this message because you are subscribed to the Google Groups 
"Django users" group.
To post to this group, send email to django-users@googlegroups.com
To unsubscribe from this group, send email to 
django-users+unsubscr...@googlegroups.com
For more options, visit this group at 
http://groups.google.com/group/django-users?hl=en
-~--~~~~--~~--~--~---



Re: "django-pagination" and generic.views.date_based.archive_index()

2009-10-18 Thread Mihail Lukin

Look at date_based.py:

if date_list and num_latest:
latest = queryset.order_by('-'+date_field)[:num_latest]
else:
latest = None

So, if you use num_latest=None, you will always get the whole list.

On Aug 30, 2:47 pm, tezro  wrote:
> Anyone?
>
> On Aug 14, 8:29 am, tezro  wrote:
>
> > The question is that "django.views.generic.date_based.archive_index()"
> > takes an optional argument "num_latest" which is 15 by default.
> > Setting it manually to num_latest=10 is way off to correct to
> > me. It works. I suppose that it even doesn't retrieve all the tons of
> > data from the DB, but what if I have 10 + 1 record :)
>
> > What's the right way to use "django-pagination" and the "archive_index
> > ()" or am I missing something?
>
> > Example code.
> > ___
>
> > def index(request):
> >         qs = News.objects.filter(is_published=1)
> >         return archive_index(request, qs, 'date', num_latest=1)
> > ___
>
> > Thanks.
--~--~-~--~~~---~--~~
You received this message because you are subscribed to the Google Groups 
"Django users" group.
To post to this group, send email to django-users@googlegroups.com
To unsubscribe from this group, send email to 
django-users+unsubscr...@googlegroups.com
For more options, visit this group at 
http://groups.google.com/group/django-users?hl=en
-~--~~~~--~~--~--~---



Re: django pagination

2009-09-05 Thread Karen Tracey
On Sat, Sep 5, 2009 at 4:52 PM, Michael Ralan  wrote:

>
> Hi,
>
> Apologies if this question has been asked before but I was not able to
> find a satisfactory answer.
>
> In the django admin app there is a capability to have a pagination
> object that lists the number of pages that can be paged.
>
> I have found code that uses the django Paginator object which builds a
> navbar that looks like this
>
>  previous
>
> The documentation for the Paginator tag (seems to be non-native) on
> the django site shows what I want. But is an example that uses a
> custom template. This is also clearly a custom tag.
>
> How do I use the django admin navbar in my app? I want it to display
> something like
>
> [1] [2] [3] [...] [30]
>
> and do it natively.
>
>
I don't know what you mean by native and non-native.  Admin builds that list
of possible pages you can jump to using its own custom tag, the heart of the
code is here:


http://code.djangoproject.com/browser/django/tags/releases/1.1/django/contrib/admin/templatetags/admin_list.py#L28

The tags used by the admin are generally not documented for use by other
apps.  Thus there is no direct way to "paginate like admin", but the source
is freely available so you can certainly borrow it.

Karen

--~--~-~--~~~---~--~~
You received this message because you are subscribed to the Google Groups 
"Django users" group.
To post to this group, send email to django-users@googlegroups.com
To unsubscribe from this group, send email to 
django-users+unsubscr...@googlegroups.com
For more options, visit this group at 
http://groups.google.com/group/django-users?hl=en
-~--~~~~--~~--~--~---



Re: "django-pagination" and generic.views.date_based.archive_index()

2009-08-30 Thread tezro

Anyone?

On Aug 14, 8:29 am, tezro  wrote:
> The question is that "django.views.generic.date_based.archive_index()"
> takes an optional argument "num_latest" which is 15 by default.
> Setting it manually to num_latest=10 is way off to correct to
> me. It works. I suppose that it even doesn't retrieve all the tons of
> data from the DB, but what if I have 10 + 1 record :)
>
> What's the right way to use "django-pagination" and the "archive_index
> ()" or am I missing something?
>
> Example code.
> ___
>
> def index(request):
>         qs = News.objects.filter(is_published=1)
>         return archive_index(request, qs, 'date', num_latest=1)
> ___
>
> Thanks.
--~--~-~--~~~---~--~~
You received this message because you are subscribed to the Google Groups 
"Django users" group.
To post to this group, send email to django-users@googlegroups.com
To unsubscribe from this group, send email to 
django-users+unsubscr...@googlegroups.com
For more options, visit this group at 
http://groups.google.com/group/django-users?hl=en
-~--~~~~--~~--~--~---