Skip to main content

Recent objects fetching utilities

Project description

Recent objects fetching utilities

Usage:

from testapp.models import Article, Comment, Payment

from recent_objects.recent_objects import RecentObjects

ro = RecentObjects(
    [
        {
            "queryset": Article.objects.all(),
            "date_field": "created_at",
        },
        {
            "queryset": Comment.objects.all(),
            "date_field": "created_at",
        },
        {
            "queryset": Payment.objects.all(),
            "date_field": "created_at",
        },
    ]
)

recent_10_objects = ro.page(paginate_by=10, page=1)

recent_10_objects will now be a list of up to 10 dictionaries of the form:

[
  {
      "type": "testapp.article",
      "date": datetime(...),
      "pk": 24,
      "object": Article(),
  },
  {
      "type": "testapp.comment",
      "date": datetime(...),
      "pk": 42,
      "object": Comment(),
  },
  ...
]

You can optionally specify the type yourself in the recent objects spec above. This may be useful when you want more control over the value or if you’re assembling several querysets using the same underlying model.

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_recent_objects-0.1.0.tar.gz (4.1 kB view hashes)

Uploaded Source

Built Distribution

django_recent_objects-0.1.0-py3-none-any.whl (4.3 kB view hashes)

Uploaded Python 3

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