79400535

Date: 2025-01-30 16:23:03
Score: 1
Natty:
Report link

Django managers are classes that manage the database query operations on a particular model. Django model manager

Proxy models allow you to create a new model that inherits from an existing model but does not create a new database table. proxy model

Let me give you an example:

class Book(models.Model):
    title = models.CharField(max_length=100)
    author = models.CharField(max_length=100)
    published_date = models.DateField()
    is_downloadable = models.BooleanField(default=True)

If this is your model

manager:

class BookMnanger(models.Manager):
    def by_link(self):
        return self.filter(is_downloadable=True)

and you new manager:

class Book(models.Model):
    title = models.CharField(max_length=100)
    author = models.CharField(max_length=100)
    published_date = models.DateField()
    is_downloadable = models.BooleanField(default=True)
    # you new manager
    downloading = BookMnanger()

now, your new custom manager can work as below:

my_books = Book.downloading.all()
print(my_books)

but the proxy:

class BookProxy(Book):
    class Meta:
        proxy = True

    def special_method(self):
        return f"{self.title} by {self.author}, published on {self.published_date}"

and your proxy can work like this:

book = BookProxy.objects.first() 
print(book.special_method()) 

proxies are the way to change behavior of your model but, managers will change your specific queries

I can give you more link about them, if you need?

Reasons:
  • Long answer (-1):
  • Has code block (-0.5):
  • Ends in question mark (2):
  • Low reputation (0.5):
Posted by: Mehdi