class Portfolio(models.Model):
client = models.ForeignKey(Client, on_delete=models.CASCADE, related_name='portfolio')
name = models.CharField('название', max_length=255)
def get_portfolio(self):
return self.objects.filter(name='123').all()
class Model(ModelBase):
some = models.CharField(_("Что то "), max_length=250)
@classmethod
def get_model(cls):
return cls.objects.filter(title__icontains="123")
from core.models import Model
Model.get_model()
<QuerySet []>
m1 = Model(title="123")
m1.save()
Model.get_model()
<QuerySet [<Model: 123>]>
from django.db import models
class PortfolioManager(models.Manager):
def get_portfolio(self):
return self.get_queryset.filter(name='123')
class Portfolio(models.Model):
client = models.ForeignKey(Client, on_delete=models.CASCADE, related_name='portfolio')
name = models.CharField('название', max_length=255)
objects = PortfolioManager()
Portfolio.objects.get_portfolio()