Business
Jobs
  • About Us
  • Solutions
    • Job Postings
      Post your job and receive qualified candidates in 48h.
    • Candidate Assessments
      500+ technical and psychological tests, plus anti-fraud.
    • Headhunting
      Tailor-made executive search from start to finish.
    • Payroll + EOR
      Payroll dispersal and EOR across 15+ LATAM countries.
  • Pricing
  • Jobs

0

267
Views
FastApi pagination error using fastapi-contrib

I'm trying to add pagination to my fastapi project. So I decide to use this:

fastapi-contrib

I follow the same example there, but for some reason I'm getting this error:

type object 'MOrdenesTrabajo' has no attribute 'count'

Here is my code, thanks for your help!!

route

@router.get("/ordenes-trabajo")
async def read_ot(pagination: Pagination = Depends(), db: Session =Depends(get_db)):
   filter_kwargs = {}
  return await pagination.paginate(serializer_class=OtSerializer.MOrdenesTrabajo, **filter_kwargs)

Pydantic model

class MOrdenesTrabajo(ModelSerializer):

   class Meta:
    model = OT # <---Model below

Sqlalchemy model

class MOrdenesTrabajo(Base):
__tablename__ = 'M_ordenesTrabajos'

idordenesTrabajos = Column(Integer, primary_key=True)
fecCreacion = Column(Date)
fecModificacion = Column(Date)
estado = Column(Integer)
descripcion = Column(Text)
nombre = Column(String(100))
documento = Column(Text)
fechaOrden = Column(Date)
numero = Column(Text)
ot_padre = Column(Integer)
data = Column(JSON)
over 4 years ago · Santiago Trujillo
1 answers
Answer question

0

I think you should use sqlalchemy-filters. I am using it for pagination in my FastAPI project and it works as expected. My code for pagination looks like this:

# pagination
num_of_pages = 0
total_results = 0
if skip and limit:
    results, pagination = apply_pagination(
         results,
         page_number=skip,
         page_size=limit
    )
    num_of_pages = pagination.num_pages
    total_results = pagination.total_results
over 4 years ago · Santiago Trujillo Report
Answer question
Find remote jobs

Discover the new way to find a job!

Top jobs
Top job categories
Business
Post vacancy Pricing Sales
Legal
Terms and conditions Privacy policy
© 2026 PeakU Inc. All Rights Reserved.
Andres GPT
Show me some job opportunities
There's an error!