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.


Django Pagination paginate dictionary of objects

2020-07-28 Thread Harvindar Singh Garcha
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.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.


Django Pagination paginate dictionary of objects

2020-07-28 Thread Harvindar Singh Garcha
I am new to Django, and trying to paginate a dictionary objects, I am 
calling stackoverflow API where I want the result to get paginated. However 
I am unable to so and not getting what's wrong with my code. 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
>
>  })
>
>>
>>

My template file


{%if data %}
 
 
 
 
 {% for key,value in data.items %}
 
 
 {{ value.title }}
 {{ value.creation_date }} 
  Asked By
 {{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 %}







*Can someone tell me what's wrong with my code, I am unable to get a 
paginated result, everything is coming all together on single page.*




-- 
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/683ad3c2-16d6-4eea-9074-5336251165aeo%40googlegroups.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.


Django Pagination

2020-05-30 Thread Akshat Zala
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.


Re: how to use django pagination with sql query and not ORM

2019-09-24 Thread Deep Sukhwani
Have you tried using the *.query* on Django's QuerySet (documentation: [1])

For example, if my QuerySet is:
*User.objects.filter(username__contains='alpha')*

I can obtain the underlying raw SQL Query using:
*print(User.objects.filter(username__contains='alpha').query)*
*>>> *print(User.objects.filter(username__contains='alpha').query)
SELECT `auth_user`.`id`, `auth_user`.`password`, `auth_user`.`last_login`,
`auth_user`.`is_superuser`, `auth_user`.`username`,
`auth_user`.`first_name`, `auth_user`.`last_name`, `auth_user`.`email`,
`auth_user`.`is_staff`, `auth_user`.`is_active`, `auth_user`.`date_joined`
FROM `auth_user` WHERE `auth_user`.`username` LIKE BINARY %alpha%

1:
https://docs.djangoproject.com/en/2.2/topics/db/sql/#performing-raw-queries

--
Regards
Deep L Sukhwani


On Wed, 25 Sep 2019 at 00:47, leb dev  wrote:

> I now how to use django pagination with ORM django after filtering the
> required data and put in into *pagination div*
>
> *queryset_list = employee.objects.all()*
> *query=request.GET.get("q")*
> *if query:*
> *queryset_list=queryset_list.filter(*
> *  Q(name__icontains=query)|*
> *  Q(father_name__icontains=query)|*
> *  Q(mother_name__icontains=query)|*
> *  Q(content__icontains=query)|*
> *  Q(create_date__icontains=query)*
> *  # Q(user__first_name__contains=query)*
> *).distinct()*
>
>
> *paginator = Paginator(queryset_list, 5)*
> *page_request_var = "page"*
> *page = request.GET.get(page_request_var)*
> *queryset = paginator.get_page(page)*
>
> *context={*
> *"object_list":queryset,*
> *"title":"List Items",*
> *"page_request_var":page_request_var,*
> *}*
> *return render(request,"blog/list.html", context)*
>
>
> the above code is working
>
> my question is how to convert this ORM into raw SQL
>
> i know that i must use LIMIT and OFFSET  in raw SQL  to embedded into
> paginator.
>
>
>
> --
> 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/2d44b204-8520-423a-992c-597fd479f856%40googlegroups.com
> <https://groups.google.com/d/msgid/django-users/2d44b204-8520-423a-992c-597fd479f856%40googlegroups.com?utm_medium=email_source=footer>
> .
>

-- 
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/CAEMqiPc5zqcT%2BaPYSySLCJe22nPC-fCk_RkaTvWvRx5CSqkXQA%40mail.gmail.com.


how to use django pagination with sql query and not ORM

2019-09-24 Thread leb dev
I now how to use django pagination with ORM django after filtering the 
required data and put in into *pagination div*

*queryset_list = employee.objects.all()*
*query=request.GET.get("q")*
*if query:*
*queryset_list=queryset_list.filter(*
*  Q(name__icontains=query)|*
*  Q(father_name__icontains=query)|*
*  Q(mother_name__icontains=query)|*
*  Q(content__icontains=query)|*
*  Q(create_date__icontains=query)*
*  # Q(user__first_name__contains=query)*
*).distinct()*


*paginator = Paginator(queryset_list, 5)*
*page_request_var = "page"*
*page = request.GET.get(page_request_var)*
*queryset = paginator.get_page(page)*

*context={*
*"object_list":queryset,*
*"title":"List Items",*
*"page_request_var":page_request_var,*
*}*
*return render(request,"blog/list.html", context)*


the above code is working 

my question is how to convert this ORM into raw SQL 

i know that i must use LIMIT and OFFSET  in raw SQL  to embedded into 
paginator.



-- 
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/2d44b204-8520-423a-992c-597fd479f856%40googlegroups.com.


Re: Using django pagination or slicing

2016-10-31 Thread ADEWALE ADISA
Thanks fedowag.
On Oct 31, 2016 12:01 PM, "王安刚" <fedo...@gmail.com> wrote:

> hi
> i prefer method 2
>
> you can get all the list from db and store it in redis using zadd
> each time an ajax request comes, you get the data you need using zrange
>
>
> 在 2016年10月31日星期一 UTC+8上午9:05:07,ADEWALE ADISA写道:
>>
>> Hello,
>> Please I need an advice on the best approach to take on the following
>> issues.
>> I have a database table consist of about 1000 record. I need to be
>> displaying like 20 records at a time on a page such that when the user
>> scroll the browser another batches will be append to the browser.
>> Below are the 3 ways am aiming to achieve this:
>>
>> 1. Using django pagination feature.
>>
>> 2. Everytime records need to be appended to the browser , an ajax call is
>> made to the view, then the queryset is slice using appropriate lower and
>> upper band. Then the returned record is appended to the browser.
>>
>> 3. Fetch the whole records from the database and transfer everything to
>> the browser, then JavaScript is now use to slice and be appending as needed.
>>
>> NOTE: The webpage would work like yahoo.com mobile site.
>> Please with approach is the best in term of performance and speed.
>>
>> Thanks.
>>
> --
> 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/022fd700-0edb-419c-9a0d-6e9714229599%40googlegroups.com
> <https://groups.google.com/d/msgid/django-users/022fd700-0edb-419c-9a0d-6e9714229599%40googlegroups.com?utm_medium=email_source=footer>
> .
> For more options, visit https://groups.google.com/d/optout.
>

-- 
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/CAMGzuy-s8X495UAXuQTibAXe9VLumhMvSUEhzo_rb55T4%3DsQ7g%40mail.gmail.com.
For more options, visit https://groups.google.com/d/optout.


Re: Using django pagination or slicing

2016-10-31 Thread ADEWALE ADISA
Thanks very much Ludovic for the advice.
On Oct 31, 2016 9:53 AM, "ludovic coues" <cou...@gmail.com> wrote:

> I would use 1 + 2 from your list.
>
> 3 might work on 1000 record, depending on how much data there is per
> record. But if you grow to more than 10,000 record, the page loading
> can take minutes. I have experienced that issue with two different
> project.
>
> Django pagination by itself won't give you the infinite scroll you are
> expecting. But it should give you an easy interface for slicing the
> data from your db.
>
> An easier way might be class based view. The following exemple create
> a view to a list of object, paginated:
>
> from django.http import JsonResponse
> from django.views.generic import ListView
>
> class ModelListView(ListView):
> model = RecordModel
> paginate_by = 20
>
> It will try to use the template at app/record_model_list.html, the
> context will have the keys paginator, page, is_paginated, object_list.
> You can override the method render_to_response to return a json
> response.
> The documentation on ListView is at [1] and there is an exemple for
> returning JsonResponse at [2]
>
>
> [1] https://docs.djangoproject.com/en/1.10/topics/class-
> based-views/generic-display/
> [2] https://docs.djangoproject.com/en/1.10/topics/class-
> based-views/mixins/#more-than-just-html
>
>
>
>
> 2016-10-31 2:04 GMT+01:00 ADEWALE ADISA <solixzsys...@gmail.com>:
> > Hello,
> > Please I need an advice on the best approach to take on the following
> > issues.
> > I have a database table consist of about 1000 record. I need to be
> > displaying like 20 records at a time on a page such that when the user
> > scroll the browser another batches will be append to the browser.
> > Below are the 3 ways am aiming to achieve this:
> >
> > 1. Using django pagination feature.
> >
> > 2. Everytime records need to be appended to the browser , an ajax call is
> > made to the view, then the queryset is slice using appropriate lower and
> > upper band. Then the returned record is appended to the browser.
> >
> > 3. Fetch the whole records from the database and transfer everything to
> the
> > browser, then JavaScript is now use to slice and be appending as needed.
> >
> > NOTE: The webpage would work like yahoo.com mobile site.
> > Please with approach is the best in term of performance and speed.
> >
> > Thanks.
> >
> > --
> > 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/CAMGzuy8cK7ueHGPwuCjbrV-
> SdfZwkYYhg7_t7-Dmmt%3D6g787YA%40mail.gmail.com.
> > For more options, visit https://groups.google.com/d/optout.
>
>
>
> --
>
> Cordialement, Coues Ludovic
> +336 148 743 42
>
> --
> 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/CAEuG%2BTaPWphYQAwa9-rPW5VZ93yyA3kL%
> 3Dz8JAecdLRMiKdjihA%40mail.gmail.com.
> For more options, visit https://groups.google.com/d/optout.
>

-- 
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/CAMGzuy_Tu7mdL4RTvNGWY%3Dm5PL0ttT4wv9QKeMfiLqd43MiaVw%40mail.gmail.com.
For more options, visit https://groups.google.com/d/optout.


Re: Using django pagination or slicing

2016-10-31 Thread 王安刚
hi 
i prefer method 2

you can get all the list from db and store it in redis using zadd
each time an ajax request comes, you get the data you need using zrange


在 2016年10月31日星期一 UTC+8上午9:05:07,ADEWALE ADISA写道:
>
> Hello,
> Please I need an advice on the best approach to take on the following 
> issues.
> I have a database table consist of about 1000 record. I need to be 
> displaying like 20 records at a time on a page such that when the user 
> scroll the browser another batches will be append to the browser. 
> Below are the 3 ways am aiming to achieve this:
>
> 1. Using django pagination feature.
>
> 2. Everytime records need to be appended to the browser , an ajax call is 
> made to the view, then the queryset is slice using appropriate lower and 
> upper band. Then the returned record is appended to the browser.
>
> 3. Fetch the whole records from the database and transfer everything to 
> the browser, then JavaScript is now use to slice and be appending as needed.
>
> NOTE: The webpage would work like yahoo.com mobile site.
> Please with approach is the best in term of performance and speed.
>
> Thanks.
>

-- 
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/022fd700-0edb-419c-9a0d-6e9714229599%40googlegroups.com.
For more options, visit https://groups.google.com/d/optout.


Re: Using django pagination or slicing

2016-10-31 Thread ludovic coues
I would use 1 + 2 from your list.

3 might work on 1000 record, depending on how much data there is per
record. But if you grow to more than 10,000 record, the page loading
can take minutes. I have experienced that issue with two different
project.

Django pagination by itself won't give you the infinite scroll you are
expecting. But it should give you an easy interface for slicing the
data from your db.

An easier way might be class based view. The following exemple create
a view to a list of object, paginated:

from django.http import JsonResponse
from django.views.generic import ListView

class ModelListView(ListView):
model = RecordModel
paginate_by = 20

It will try to use the template at app/record_model_list.html, the
context will have the keys paginator, page, is_paginated, object_list.
You can override the method render_to_response to return a json
response.
The documentation on ListView is at [1] and there is an exemple for
returning JsonResponse at [2]


[1] 
https://docs.djangoproject.com/en/1.10/topics/class-based-views/generic-display/
[2] 
https://docs.djangoproject.com/en/1.10/topics/class-based-views/mixins/#more-than-just-html




2016-10-31 2:04 GMT+01:00 ADEWALE ADISA <solixzsys...@gmail.com>:
> Hello,
> Please I need an advice on the best approach to take on the following
> issues.
> I have a database table consist of about 1000 record. I need to be
> displaying like 20 records at a time on a page such that when the user
> scroll the browser another batches will be append to the browser.
> Below are the 3 ways am aiming to achieve this:
>
> 1. Using django pagination feature.
>
> 2. Everytime records need to be appended to the browser , an ajax call is
> made to the view, then the queryset is slice using appropriate lower and
> upper band. Then the returned record is appended to the browser.
>
> 3. Fetch the whole records from the database and transfer everything to the
> browser, then JavaScript is now use to slice and be appending as needed.
>
> NOTE: The webpage would work like yahoo.com mobile site.
> Please with approach is the best in term of performance and speed.
>
> Thanks.
>
> --
> 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/CAMGzuy8cK7ueHGPwuCjbrV-SdfZwkYYhg7_t7-Dmmt%3D6g787YA%40mail.gmail.com.
> For more options, visit https://groups.google.com/d/optout.



-- 

Cordialement, Coues Ludovic
+336 148 743 42

-- 
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/CAEuG%2BTaPWphYQAwa9-rPW5VZ93yyA3kL%3Dz8JAecdLRMiKdjihA%40mail.gmail.com.
For more options, visit https://groups.google.com/d/optout.


Using django pagination or slicing

2016-10-30 Thread ADEWALE ADISA
Hello,
Please I need an advice on the best approach to take on the following
issues.
I have a database table consist of about 1000 record. I need to be
displaying like 20 records at a time on a page such that when the user
scroll the browser another batches will be append to the browser.
Below are the 3 ways am aiming to achieve this:

1. Using django pagination feature.

2. Everytime records need to be appended to the browser , an ajax call is
made to the view, then the queryset is slice using appropriate lower and
upper band. Then the returned record is appended to the browser.

3. Fetch the whole records from the database and transfer everything to the
browser, then JavaScript is now use to slice and be appending as needed.

NOTE: The webpage would work like yahoo.com mobile site.
Please with approach is the best in term of performance and speed.

Thanks.

-- 
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/CAMGzuy8cK7ueHGPwuCjbrV-SdfZwkYYhg7_t7-Dmmt%3D6g787YA%40mail.gmail.com.
For more options, visit https://groups.google.com/d/optout.


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.


django pagination

2016-01-25 Thread 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/8e0b5497-e3b3-4e62-b698-180f68e46a56%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.


Django Pagination

2013-10-03 Thread Hélio Miranda
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/b2cb773f-f8f4-43e9-ab02-0abd4e391171%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.



Django Pagination Not Working!

2012-05-06 Thread coded kid
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)})

   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)
  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 %}
previous
{% endif %}


Page {{ Asks.number }} of {{ Asks.paginator.num_pages }}.


{% if Asks.has_next %}
next
{% endif %}
 




 {% endblock %}

-- 
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.



Django - pagination - split articles manually?

2011-10-22 Thread Petey
Is it possible to split articles manually with some sort of a pagination tag 
in the text?

Whole text:

Part 1:
Lorem ipsum dolor sit amet, consectetur adipiscing elit. 
{{ split_tag.page1 }}
Part 2:
Vivamus sit amet odio a turpis congue tincidunt. 
{{ split_tag.page2 }}
etc.

-- 
You received this message because you are subscribed to the Google Groups 
"Django users" group.
To view this discussion on the web visit 
https://groups.google.com/d/msg/django-users/-/AovifMCFUbAJ.
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.



Django pagination is repeating results

2011-02-18 Thread diogobaeder
Hi,

I have this weird pagination bug in Django: using object_list as a
return of a view, but passing a "paginate_by" argument to it, it's
repeating some of the results; Otherwise, if I remove the argument or
set as "paginate_by=None", the results are correct.

If using pagination, the quantity of results is maintained at a total,
so, because there are repeated results, the last results are left out
of the list, so they don't appear in the template.

Any ideas of what might be happening?

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

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.



django pagination

2010-08-06 Thread bulya911
I can't find a mistake :-(( {{ autopaginate product 2 }} is working,
because of only two products I see, but {{ paginate }} is NOT, its
returns just nothing
Here my template:
{% load i18n %}
{% load pagination_tags %}
{% autopaginate product 2 %}


 Delete All | Another Action
{{ paginate }}



{% for p in product %}



{{ p.name_english }}
{% if p.fob_price_from %} {{ p.fob_price_from }} {%
else %} - {% endif %}
{% if p.min_order_quantity %}
{{ p.min_order_quantity }} {% else %} - {% endif %}
{% trans "Edit" %} {%
trans "Delete" %}

{% endfor %}



-- 
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: One to many django pagination

2010-06-22 Thread jx jx
Oh, i guess i didn't define my models using the "through" relationship.
Thanks for the help! :)

On Tue, Jun 22, 2010 at 4:10 PM, euan.godd...@googlemail.com <
euan.godd...@gmail.com> wrote:

> If i understand you correctly you've got a couple of solutions. You
> can define a "through" relationship between Student and Teacher usinf
> Techer_profile as the "through" table (http://docs.djangoproject.com/
> en/dev/topics/db/models/#extra-fields-on-many-to-many-relationships<http://docs.djangoproject.com/%0Aen/dev/topics/db/models/#extra-fields-on-many-to-many-relationships>
> ).
> Then you should be able to do:
>
> teachers = Teacher.objects.filter(student__name="Jonny")
>
> I think the ORM should take care of this query for you and select only
> those teachers.
>
> Euan
>
> On Jun 22, 3:39 am, Jx <l3earl3ea...@gmail.com> wrote:
> > Hi,
> >
> > i recently encountered a problem due to inefficient performance of
> > django pagination. After researching, i realized that there is a need
> > to use django database queries when dealing with django-pagination as
> > "LIMIT" will automatically be added. This is useful especially when
> > dealing with huge chunk of data.
> >
> > However, i came across a problem where i could not figure out how to
> > use django database query to extract the data.
> >
> > Lets say i have 3 tables, "Teachers", "Students", and
> > "Teachers_profile" with a one-many relationship.
> >
> > The Teacher table contains teacher_id,.(teacher info)
> > The Student table contains student_id,name,...(student info)
> > The Teacher_profile table is the link between the 2 tables. It
> > contains teacher_id,student_id
> >
> > How can i use django database query with filters to extract the
> > teachers who is managing a student named "Jonny" for example?
> >
> > i'm not sure if this is an easy question, but i'm having some trouble
> > in solving it :(
>
> --
> 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<django-users%2bunsubscr...@googlegroups.com>
> .
> For more options, visit this group at
> http://groups.google.com/group/django-users?hl=en.
>
>

-- 
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: One to many django pagination

2010-06-22 Thread euan.godd...@googlemail.com
If i understand you correctly you've got a couple of solutions. You
can define a "through" relationship between Student and Teacher usinf
Techer_profile as the "through" table (http://docs.djangoproject.com/
en/dev/topics/db/models/#extra-fields-on-many-to-many-relationships).
Then you should be able to do:

teachers = Teacher.objects.filter(student__name="Jonny")

I think the ORM should take care of this query for you and select only
those teachers.

Euan

On Jun 22, 3:39 am, Jx <l3earl3ea...@gmail.com> wrote:
> Hi,
>
> i recently encountered a problem due to inefficient performance of
> django pagination. After researching, i realized that there is a need
> to use django database queries when dealing with django-pagination as
> "LIMIT" will automatically be added. This is useful especially when
> dealing with huge chunk of data.
>
> However, i came across a problem where i could not figure out how to
> use django database query to extract the data.
>
> Lets say i have 3 tables, "Teachers", "Students", and
> "Teachers_profile" with a one-many relationship.
>
> The Teacher table contains teacher_id,.(teacher info)
> The Student table contains student_id,name,...(student info)
> The Teacher_profile table is the link between the 2 tables. It
> contains teacher_id,student_id
>
> How can i use django database query with filters to extract the
> teachers who is managing a student named "Jonny" for example?
>
> i'm not sure if this is an easy question, but i'm having some trouble
> in solving it :(

-- 
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.



One to many django pagination

2010-06-21 Thread Jx
Hi,

i recently encountered a problem due to inefficient performance of
django pagination. After researching, i realized that there is a need
to use django database queries when dealing with django-pagination as
"LIMIT" will automatically be added. This is useful especially when
dealing with huge chunk of data.

However, i came across a problem where i could not figure out how to
use django database query to extract the data.

Lets say i have 3 tables, "Teachers", "Students", and
"Teachers_profile" with a one-many relationship.

The Teacher table contains teacher_id,.(teacher info)
The Student table contains student_id,name,...(student info)
The Teacher_profile table is the link between the 2 tables. It
contains teacher_id,student_id

How can i use django database query with filters to extract the
teachers who is managing a student named "Jonny" for example?

i'm not sure if this is an easy question, but i'm having some trouble
in solving it :(

-- 
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: question about django-pagination

2009-12-19 Thread Rodrigo Cea
You can paginate whatever you want. From the docs:

"Note that you can give Paginator a list/tuple, a Django QuerySet, or
any other object with a count() or __len__() method. "

On Dec 19, 3:33 am, Continuation <selforgani...@gmail.com> wrote:
> In the django-pagination, it uses the example:
> {% autopaginate object_list %}
>
> My question is does object_list have to be the **entire** list over
> which I want to paginate, or can I limit the length of object_list? If
> I limit the length of object_list, will autopaginate still go through
> the entire list?
>
> As an example, say I want to paginate over the list a.field_set.all().
> Let's say that list has 1 objects. I might not want my database to
> return such a large result set. So I might want to do something like:
>
> object_list = a.field_set()[:5]
>
> Now if I use {% autopaginate object_list %} in my template, would I
> still be able to paginate over the entire list of 1 objects? Or my
> list would be shortened to 5 objects?

--

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: question about django-pagination

2009-12-18 Thread Lakshman Prasad
> would I still be able to paginate over the entire list of 1 objects?
Or my list would be shortened to 5 objects?

Its the latter. Your query set will loop only for the size of it's length.


On Sat, Dec 19, 2009 at 12:03 PM, Continuation <selforgani...@gmail.com>wrote:

> In the django-pagination, it uses the example:
> {% autopaginate object_list %}
>
> My question is does object_list have to be the **entire** list over
> which I want to paginate, or can I limit the length of object_list? If
> I limit the length of object_list, will autopaginate still go through
> the entire list?
>
> As an example, say I want to paginate over the list a.field_set.all().
> Let's say that list has 1 objects. I might not want my database to
> return such a large result set. So I might want to do something like:
>
> object_list = a.field_set()[:5]
>
> Now if I use {% autopaginate object_list %} in my template, would I
> still be able to paginate over the entire list of 1 objects? Or my
> list would be shortened to 5 objects?
>
> --
>
> 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<django-users%2bunsubscr...@googlegroups.com>
> .
> For more options, visit this group at
> http://groups.google.com/group/django-users?hl=en.
>
>
>


-- 
Regards,
Lakshman
becomingguru.com
lakshmanprasad.com

--

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.




question about django-pagination

2009-12-18 Thread Continuation
In the django-pagination, it uses the example:
{% autopaginate object_list %}

My question is does object_list have to be the **entire** list over
which I want to paginate, or can I limit the length of object_list? If
I limit the length of object_list, will autopaginate still go through
the entire list?

As an example, say I want to paginate over the list a.field_set.all().
Let's say that list has 1 objects. I might not want my database to
return such a large result set. So I might want to do something like:

object_list = a.field_set()[:5]

Now if I use {% autopaginate object_list %} in my template, would I
still be able to paginate over the entire list of 1 objects? Or my
list would be shortened to 5 objects?

--

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, Михаил Лукин <mihail.lu...@googlemail.com> 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 <tezro...@gmail.com>
>
>
>
>
>
> > Surely I could use the list_detail.object_list, but the use of date
> > based generics though ))
>
> > On Oct 18, 11:45 pm, Михаил Лукин <mihail.lu...@googlemail.com> 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 <tezro...@gmail.com>
>
> > > > 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 <mihail.lu...@googlemail.com> 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 <tezro...@gmail.com> wrote:
>
> > > > > > Anyone?
>
> > > > > > On Aug 14, 8:29 am, tezro <tezro...@gmail.com> 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 <tezro...@gmail.com>

>
> Surely I could use the list_detail.object_list, but the use of date
> based generics though ))
>
>
> On Oct 18, 11:45 pm, Михаил Лукин <mihail.lu...@googlemail.com> 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 <tezro...@gmail.com>
> >
> >
> >
> >
> >
> > > 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 <mihail.lu...@googlemail.com> 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 <tezro...@gmail.com> wrote:
> >
> > > > > Anyone?
> >
> > > > > On Aug 14, 8:29 am, tezro <tezro...@gmail.com> 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, Михаил Лукин <mihail.lu...@googlemail.com> 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 <tezro...@gmail.com>
>
>
>
>
>
> > 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 <mihail.lu...@googlemail.com> 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 <tezro...@gmail.com> wrote:
>
> > > > Anyone?
>
> > > > On Aug 14, 8:29 am, tezro <tezro...@gmail.com> 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 <tezro...@gmail.com>

>
> 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 <mihail.lu...@googlemail.com> 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 <tezro...@gmail.com> wrote:
> >
> > > Anyone?
> >
> > > On Aug 14, 8:29 am, tezro <tezro...@gmail.com> 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 <mihail.lu...@googlemail.com> 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 <tezro...@gmail.com> wrote:
>
> > Anyone?
>
> > On Aug 14, 8:29 am, tezro <tezro...@gmail.com> 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 <tezro...@gmail.com> wrote:
> Anyone?
>
> On Aug 14, 8:29 am, tezro <tezro...@gmail.com> 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 100000 + 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
-~--~~~~--~~--~--~---



django pagination

2009-09-05 Thread Michael Ralan

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.

Thanks, and regards


--~--~-~--~~~---~--~~
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 <tezro...@gmail.com> 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
-~--~~~~--~~--~--~---



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

2009-08-13 Thread tezro

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
-~--~~~~--~~--~--~---



django-pagination with search form

2009-08-06 Thread Streamweaver

Simple Pagination in Django is great but I'm having some trouble with
the best way to design pagination with querysets derived from Search
Forms.

I'm currently using the Django-Pagination middleware and it works
great but there's really pretty bad documentation on it (as with many
projects) and I can't figure the best way to pass search form
parameters between pages.

Is there a recommended Django way to handle this? GET paams, Sessions,
Cache?

I'm surprised I can't find more discussion or examples on this so that
could indicate I'm missing something very obvious and apologize before
hand if I am but could use a point in the right direction.
--~--~-~--~~~---~--~~
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
-~--~~~~--~~--~--~---