diff --git a/README.md b/README.md index d2d49a0..ed19cae 100644 --- a/README.md +++ b/README.md @@ -27,11 +27,15 @@ from DjangoEasyScoping.ScopingMixin import ScopingMixin, ScopingQuerySet ### Implementing Mix `ScopingMixin` in with the Django model(s) you'd like to create scopes for. + +For example, in the [purchases](https://net-prophet.github.io/django-easy-scoping/docs/usage.html#purchases-modelspy) model: ```python class Purchase(ScopingMixin, models.Model): ``` -Override the Queryset for that model using `ScopingQuerySet`. +Override the Queryset for that model using `ScopingQuerySet`. By default, the override's name must be `objects` +(see [below](https://net-prophet.github.io/django-easy-scoping/docs/installation.html#implementing-with-existing-managers-querysets) + for changing the default). ```python objects = ScopingQuerySet.as_manager() ``` @@ -41,40 +45,40 @@ 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: +You only need to take action if you'd like to replace the default name (`objects`) +of the ScopingQuerySet override, for instance: ```python other_name = ScopingQuerySet.as_manager() ``` -Then simply open `ScopingMixin.py` in your `sites-packages` and edit the following -methods. +Then, simply open `ScopingMixin.py` in your `sites-packages` and edit the following +methods on lines 6 and 11. ```python -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) +1 class ScopingMixin(object): +2 +3 @classmethod +4 def get_scope(cls, name) +5 if hasattr(cls, '__scopes__') and name in cls.scopes(): +6 return getattr(cls.objects.all(), name) +7 +8 @classmethod +9 def get_aggregate(cls, name) +10 if hasattr(cls, '__aggregate__') and name in cls.aggregates(): +11 return getattr(cls.objects.all(), name) ``` becomes ```python -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) +1 class ScopingMixin(object): +2 +3 @classmethod +4 def get_scope(cls, name) +5 if hasattr(cls, '__scopes__') and name in cls.scopes(): +6 return getattr(cls.other_name.all(), name) +7 +8 @classmethod +9 def get_aggregate(cls, name) +10 if hasattr(cls, '__aggregate__') and name in cls.aggregates(): +11 return getattr(cls.other_name.all(), name) ```