Here's the code:
class CarSource
class CarSource(models.Model):
status = models.CharField(max_length=1, blank=True, null=True)
dealer = models.ForeignKey(Dealer, blank=True, null=True, \
on_delete=models.SET_NULL, related_name='cars', \
verbose_name=u'dealer own this car')
objects = CarSourceManager()
class Dealer
class Dealer(models.Model):
...
class CarSourceManager:
class CarSourceManager(models.Manager):
''' Manage query in CarSource, filter data that was processed successfully.'''
def get_query_set(self):
return super(self.__class__, self).get_query_set().filter(status='S')
When I execute this:
from ... import Dealer
d = Dealer.objects.get(id = 2)
d.cars.all()
It occur error as below:
File "/...path..of..error..file../apps/car/managers.py", line 9, in all
return super(self.__class__, self).all().filter(status='S')
File "/...path..of..error..file../apps/car/managers.py", line 9, in all
return super(self.__class__, self).all().filter(status='S')
File "/...path..of..error..file../apps/car/managers.py", line 9, in all
return super(self.__class__, self).all().filter(status='S')
File "/...path..of..error..file../apps/car/managers.py", line 9, in all
return super(self.__class__, self).all().filter(status='S')
File "/...path..of..error..file../apps/car/managers.py", line 9, in all
return super(self.__class__, self).all().filter(status='S')
File "/...path..of..error..file../apps/car/managers.py", line 9, in all
return super(self.__class__, self).all().filter(status='S')
File "/...path..of..error..file../apps/car/managers.py", line 9, in all
return super(self.__class__, self).all().filter(status='S')
RuntimeError: maximum recursion depth exceeded while calling a Python object
I overwrite the get_query_set
of models.Manager
in CarSourceManager
, obviously, it continue call it self recursively. I've watched the code of Manager but can't figure it out, please help me.