Skip to content

Instantly share code, notes, and snippets.

@slavama
Created February 13, 2019 07:10
Show Gist options
  • Save slavama/eb47b7d9a109ead1b1686793f1f24e10 to your computer and use it in GitHub Desktop.
Save slavama/eb47b7d9a109ead1b1686793f1f24e10 to your computer and use it in GitHub Desktop.
Расширить менеджер модели в DJANGO
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