Skip to main content

A mixin to allow users to create scopes on Django models.

Project description

Django Easy Scoping allows you to register scopes and aggregate functions on your Django models.

Installation

To get the ScopingMixin.py file you can download it or use pip.

Downloading File

Download the ScopingMixin file from github. ScopingMixin.py

Import ScopingMixin and ScopingQuerySet from ScopingMixin.py.

from <path to file>.ScopingMixin import ScopingMixin, ScopingQuerySet

Using pip

$ pip install django-easy-scoping

Import ScopingMixin and ScopingQuerySet from ScopingMixin.py.

from DjangoEasyScoping.ScopingMixin import ScopingMixin, ScopingQuerySet

Implementing

Mix ScopingMixin in with the Django model(s) you'd like to create scopes for.

class Purchase(ScopingMixin, models.Model):

Override the Queryset for that model using ScopingQuerySet.

    objects = ScopingQuerySet.as_manager()

Done!

Implementing with existing Managers/Querysets

If you'd like to continue using your own custom manager/queryset then you can! You only need to take action if you'd like to name the ScopingQuerySet override something other than objects, for instance:

other_name = ScopingQuerySet.as_manager()

Then simply open ScopingMixin.py in your sites-packages and edit the following methods.

class ScopingMixin(object):

    @classmethod
    def get_scope(cls, name)
        if hasattr(cls, '__scopes__') and name in cls.scopes():
            return getattr(cls.objects.all(), name)

    @classmethod
    def get_aggregate(cls, name)
        if hasattr(cls, '__aggregate__') and name in cls.aggregates():
            return getattr(cls.objects.all(), name)

becomes

class ScopingMixin(object):

    @classmethod
    def get_scope(cls, name)
        if hasattr(cls, '__scopes__') and name in cls.scopes():
            return getattr(cls.other_name.all(), name)

    @classmethod
    def get_aggregate(cls, name)
        if hasattr(cls, '__aggregate__') and name in cls.aggregates():
            return getattr(cls.other_name.all(), name)

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-easy-scoping-1.13.tar.gz (2.8 kB view details)

Uploaded Source

Built Distribution

If you're not sure about the file name format, learn more about wheel file names.

django_easy_scoping-1.13-py3-none-any.whl (3.2 kB view details)

Uploaded Python 3

File details

Details for the file django-easy-scoping-1.13.tar.gz.

File metadata

File hashes

Hashes for django-easy-scoping-1.13.tar.gz
Algorithm Hash digest
SHA256 a6042e6ae5a14293d39f54bb83d4362495827e393b2136d22511a2df5e86b212
MD5 635863b4f1143381a98cf0ff4c2cc8ef
BLAKE2b-256 a3b5e3316d1ce57cc639f0858c6b59625ed2cca6da1d2d40ab3ae26bd9c54912

See more details on using hashes here.

File details

Details for the file django_easy_scoping-1.13-py3-none-any.whl.

File metadata

File hashes

Hashes for django_easy_scoping-1.13-py3-none-any.whl
Algorithm Hash digest
SHA256 0ee13cfc85e48f6d6075a84c52534140b67bd8273dfef31f82242b052d4cf1ff
MD5 7fcc106342053514994c1b5d0bcc5e0c
BLAKE2b-256 6e7b633c1c90879152cf30b978ae6ac5e0e169284bcc67bc7a1ddb176a10becb

See more details on using hashes here.

Supported by

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