<commit_before># `django-qmethod`

`django-qmethod` is a library for easily defining operations on collections of
Django models (that is, QuerySets and Managers).

One day, I hope something like this is included in Django core.


## Usage

Basic usage is as follows:

```python
from django.db import models
from djqmethod import Manager, querymethod

class Group(models.Model):
    pass

class Person(models.Model):
    GENDERS = dict(m='Male', f='Female', u='Unspecified').items()

    group = models.ForeignKey(Group, related_name='people')
    gender = models.CharField(max_length=1, choices=GENDERS)
    age = models.PositiveIntegerField()

    # Note: you need to create an explicit manager here.
    objects = Manager()

    @querymethod
    def minors(query):
        return query.filter(age__lt=18)

    @querymethod
    def adults(query):
        return query.filter(age__gte=18)

# The `minors()` and `adults()` methods will be available on the manager:
assert isinstance(Person.objects.minors(), models.query.QuerySet)

# They'll be available on subsequent querysets:
assert isinstance(Person.objects.filter(gender='m').minors(),
                  models.query.QuerySet)

# They'll also be available on relations, if they were mixed in to the
# default manager for that model:
group = Group.objects.all()[0]
assert isinstance(group.people.minors(), models.query.QuerySet)
```

A test project is located in `test/example/`; consult this for a more
comprehensive example.


## Installation

    pip install django-qmethod


## (Un)license

This is free and unencumbered software released into the public domain.
<commit_msg>Added pickling to the example.<commit_after># `django-qmethod`

`django-qmethod` is a library for easily defining operations on collections of
Django models (that is, QuerySets and Managers).

One day, I hope something like this is included in Django core.


## Usage

Basic usage is as follows:

```python
import cPickle as pickle
from django.db import models
from djqmethod import Manager, querymethod

class Group(models.Model):
    pass

class Person(models.Model):
    GENDERS = dict(m='Male', f='Female', u='Unspecified').items()

    group = models.ForeignKey(Group, related_name='people')
    gender = models.CharField(max_length=1, choices=GENDERS)
    age = models.PositiveIntegerField()

    # Note: you need to create an explicit manager here.
    objects = Manager()

    @querymethod
    def minors(query):
        return query.filter(age__lt=18)

    @querymethod
    def adults(query):
        return query.filter(age__gte=18)

# The `minors()` and `adults()` methods will be available on the manager:
assert isinstance(Person.objects.minors(), models.query.QuerySet)

# They'll be available on subsequent querysets:
assert isinstance(Person.objects.filter(gender='m').minors(),
                  models.query.QuerySet)

# They'll also be available on relations, if they were mixed in to the
# default manager for that model:
group = Group.objects.all()[0]
assert isinstance(group.people.minors(), models.query.QuerySet)

# The QuerySets produced are totally pickle-safe:
assert isinstance(pickle.loads(pickle.dumps(Person.objects.minors())),
                  models.query.QuerySet)
```

A test project is located in `test/example/`; consult this for a more
comprehensive example.


## Installation

    pip install django-qmethod


## (Un)license

This is free and unencumbered software released into the public domain.

{'fraction_non_alphanumeric': 0.10054739268222414, 'fraction_numerical': 0.003457216940363008, 'mean_word_length': 4.136094674556213, 'pattern_counts': {'":': 0, '<': 3, '<?xml version=': 0, '>': 3, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 0, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '2158510', 'n_tokens_mistral': 1038, 'n_tokens_neox': 982, 'n_words': 341}