Skip to content

Commit

Permalink
Updated README.md with edits in 'Documentation_Notes3.'
Browse files Browse the repository at this point in the history
  • Loading branch information
namikomatsumoto committed Jul 28, 2018
1 parent 7e8d939 commit 2dbabc0
Showing 1 changed file with 31 additions and 27 deletions.
58 changes: 31 additions & 27 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -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()
```
Expand All @@ -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)
```

0 comments on commit 2dbabc0

Please sign in to comment.