Skip to content

Commit

Permalink
added ActivatorModelManager, returns active or inactive instances of …
Browse files Browse the repository at this point in the history
…ActivatorModel
  • Loading branch information
tehfink committed Jan 20, 2010
1 parent 57e9ce9 commit 7fa216b
Showing 1 changed file with 13 additions and 0 deletions.
13 changes: 13 additions & 0 deletions django_extensions/db/models.py
Original file line number Diff line number Diff line change
Expand Up @@ -30,6 +30,18 @@ class TitleSlugDescriptionModel(models.Model):
class Meta:
abstract = True

class ActivatorModelManager(models.Manager):
""" ActivatorModelManager
Manager to return instances of ActivatorModel: SomeModel.objects.active() / .inactive()
"""
def active(self):
""" Returns active instances of ActivatorModel: SomeModel.objects.active() """
return super(ActivatorModelManager, self).get_query_set().filter(status=1)

def inactive(self):
""" Returns inactive instances of ActivatorModel: SomeModel.objects.inactive() """
return super(ActivatorModelManager, self).get_query_set().filter(status=0)

class ActivatorModel(models.Model):
""" ActivatorModel
An abstract base class model that provides activate and deactivate fields.
Expand All @@ -44,6 +56,7 @@ class ActivatorModel(models.Model):
help_text=_('keep empty for an immediate activation'))
deactivate_date = models.DateTimeField(blank=True, null=True,
help_text=_('keep empty for indefinite activation'))
objects = ActivatorModelManager()

class Meta:
abstract = True
Expand Down

0 comments on commit 7fa216b

Please sign in to comment.