diff options
author | Zygmunt Krynicki <zygmunt.krynicki@linaro.org> | 2012-07-27 16:04:52 +0200 |
---|---|---|
committer | Zygmunt Krynicki <zygmunt.krynicki@linaro.org> | 2012-07-27 16:04:52 +0200 |
commit | 44ef597f4c20e10e09bda72b794337948203128c (patch) | |
tree | b92dfefddd3436fd9d143e0fe78b93087ca21913 /license_protected_downloads | |
parent | 22a4bfeff3ed2d63816963c070acf824301f5bee (diff) |
Add LicenseManager (model manager) to License model
This manager has one convenience method to select a group of
licenses matching a list of digests.
Diffstat (limited to 'license_protected_downloads')
-rw-r--r-- | license_protected_downloads/models.py | 18 |
1 files changed, 18 insertions, 0 deletions
diff --git a/license_protected_downloads/models.py b/license_protected_downloads/models.py index d95a964..9ba3d52 100644 --- a/license_protected_downloads/models.py +++ b/license_protected_downloads/models.py @@ -1,10 +1,28 @@ from django.db import models +class LicenseManager(models.Manager): + """ + Model manager for License model. + + Provides additional convenience method + """ + + def all_with_hashes(self, hash_list): + """ + Produce a list of licenses that match the specified list of hashes. + The main use case is to convert license digest to something the user + can relate to. + """ + return self.all().filter(digest__in=hash_list) + + class License(models.Model): digest = models.CharField(max_length=40) text = models.TextField() theme = models.CharField(max_length=60) + objects = LicenseManager() + def __unicode__(self): return self.digest |