“Super in Django Manager” Kode Jawaban

Super in Django Manager

# First, define the Manager subclass.
class DahlBookManager(models.Manager):
    def get_queryset(self):
        return super().get_queryset().filter(author='Roald Dahl')

# Then hook it into the Book model explicitly.
class Book(models.Model):
    title = models.CharField(max_length=100)
    author = models.CharField(max_length=50)

    objects = models.Manager() # The default manager.
    dahl_objects = DahlBookManager() # The Dahl-specific manager.
Alive Angelfish

.save () di Django

>>> one_entry = Entry.objects.get(pk=1)
Defeated Dogfish

Jawaban yang mirip dengan “Super in Django Manager”

Pertanyaan yang mirip dengan “Super in Django Manager”

Lebih banyak jawaban terkait untuk “Super in Django Manager” di Python

Jelajahi jawaban kode populer menurut bahasa

Jelajahi bahasa kode lainnya