Skip to content

Instantly share code, notes, and snippets.

View carlossacorrea's full-sized avatar
🎯
Focusing

Carlos S Correa carlossacorrea

🎯
Focusing
  • Mexico City
  • 15:19 (UTC -06:00)
View GitHub Profile
@leonsmith
leonsmith / pagination_range.py
Last active July 6, 2020 17:22
Pagination range, used to limit huge pagination objects
from django import template
register = template.Library()
@register.filter
def pagination_range(obj, current=1, limit=10):
"""
Used with pagination page_range object when you have a lot of pages
@ivlevdenis
ivlevdenis / django_graphene_orderBy.py
Last active September 14, 2023 17:58
Django graphene orderBy
from graphene import relay, String, List
from graphene_django.filter import DjangoFilterConnectionField
from graphene_django.fields import DjangoConnectionField
from app.models import Model
class Object(DjangoObjectType):
class Meta:
model = Model
@mbrochh
mbrochh / 01_utils.py
Last active September 24, 2023 10:45
Using pagination with Django, graphene and Apollo
from django.core.paginator import EmptyPage, PageNotAnInteger, Paginator
# First we create a little helper function, becase we will potentially have many PaginatedTypes
# and we will potentially want to turn many querysets into paginated results:
def get_paginator(qs, page_size, page, paginated_type, **kwargs):
p = Paginator(qs, page_size)
try:
page_obj = p.page(page)
except PageNotAnInteger: