Skip to main content

Pull random records using Django ORM.

Project description

Pull random records using Django ORM.

Requirements

  • Python 3.8+

  • Django 3.2+

Installation

$ pip install django-random-queryset

Setup

Add RandomManager to desired model:

from django.db import models

from django_random_queryset import RandomManager


class Model(models.Model):

    objects = RandomManager()

    # ...

No database migrations are needed.

How to use it:

queryset = Model.objects.filter(field=value)
queryset.random()   # to get one random record
queryset.random(5)  # to pass limited random records
queryset.random(len(queryset)) # to get all random records
queryset.random().values()  # to have access to other queryset methods

Project details


Download files

Download the file for your platform. If you're not sure which to choose, learn more about installing packages.

Source Distribution

django-random-queryset-0.2.0.tar.gz (3.6 kB view hashes)

Uploaded Source

Supported by

AWS AWS Cloud computing and Security Sponsor Datadog Datadog Monitoring Fastly Fastly CDN Google Google Download Analytics Microsoft Microsoft PSF Sponsor Pingdom Pingdom Monitoring Sentry Sentry Error logging StatusPage StatusPage Status page