Skip to content

Commit

Permalink
Adding models docs
Browse files Browse the repository at this point in the history
  • Loading branch information
tobiaghiraldini committed Jan 25, 2019
1 parent 53c8524 commit a57bd08
Show file tree
Hide file tree
Showing 2 changed files with 35 additions and 4 deletions.
6 changes: 3 additions & 3 deletions docs/code.rst
@@ -1,16 +1,16 @@
Documentation for the Code
**************************

.. automodule:: flexible_plans
.. automodule:: django-flexible-plans.flexible_plans


Models
=========================

This is something I want to say that is not in the docstring.

.. automodule:: flexible_plans.models.plans
.. automodule:: django-flexible-plans.flexible_plans.models.plans
:members:

.. automodule:: flexible_plans.models.features
.. automodule:: django-flexible-plans.flexible_plans.models.features
:members:
33 changes: 32 additions & 1 deletion flexible_plans/models/features.py
Expand Up @@ -12,11 +12,37 @@ class BaseFeature(models.Model):
codename = models.CharField(
_('codename'), max_length=50, unique=True, db_index=True)

def get_validator(self):
"""
Get the proper validator from the ValidatorPolicy registry
:return: Validator object that matches with the feature codename or None
"""
validators = []
for validator in validators:
if validator.name == self.codename:
return validator
return None

def log_usage(self):
"""
Logs the feature usage, against the correct validator
"""
# TODO: write a base implementation, or raise an error to force a subsclass specific implementation
pass
# raise NotImplementedError()

class Meta:
abstract = True


class Feature(BaseFeature):
"""
Feature default implementation
Feature is a swappable model to allow client to use their own Feature model.
It is recommended to subclass BaseFeature to inherit all the behaviours and base fields.
Being Feature a base class of other specific Feature Classes, it support an InheritanceManager
to return all kinds of objects on Feature querysets
"""
objects = InheritanceManager()

class Meta:
Expand All @@ -25,7 +51,12 @@ class Meta:

class MeteredFeature(Feature):
units = models.PositiveIntegerField(default=0)
usage = models.PositiveIntegerField(default=0)


class CumulativeFeature(Feature):
pass
usage = models.PositiveIntegerField(default=0)


class PermissionFeature(Feature):
permission = models.ForeignKey('auth.Permission', on_delete=models.CASCADE, related_name='+')

0 comments on commit a57bd08

Please sign in to comment.