Imagine the following model, manager and queryset:
from django.db import models
class BlaQuerySet(models.QuerySet):
def annotate_field(self):
return self.annotate(bla_field=Value('Bla')
class BlaManager(models.Manager):
def get_queryset(self):
return BlaQuerySet(self.model, using=self._db).annotate_field()
class Bla(models.Model):
hello = models.CharField(max_length=10)
Now that we have the model. Let’s create something:
bla_instance = Bla.objects.create(hello='something')
bla_instance.bla_field
returns
`AttributeError: ‘Bla’ object has no attribute ‘bla_field’
On the other hand, when you filter that item:
bla_instance = Bla.objects.get(hello='something')
bla_instance.bla_field
returns the expected Bla
How can I force the create() to use my manager instead of the default one?