Created
February 13, 2019 07:10
-
-
Save slavama/eb47b7d9a109ead1b1686793f1f24e10 to your computer and use it in GitHub Desktop.
Расширить менеджер модели в DJANGO
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
class DocumentQuerySet(models.QuerySet): | |
def pdfs(self): | |
return self.filter(file_type='pdf') | |
def smaller_than(self, size): | |
return self.filter(size__lt=size) | |
class Document(models.Model): | |
name = models.CharField(max_length=30) | |
size = models.PositiveIntegerField(default=0) | |
file_type = models.CharField(max_length=10, blank=True) | |
objects = DocumentQuerySet.as_manager() |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment