我想过滤管理器中的相关条目:
class UserTravelsCarsManager(models.Manager):
def for_user(self, user):
return super(UserTravelsCarsManager, self).get_query_set().filter(user=user)
class TravelsCars(models.Model):
user = models.ForeignKey(User)
name = models.CharField(max_length=255)
...
objects = UserTravelsCarsManager()
class UserTravelsManager(models.Manager):
def for_user(self, user):
return super(UserTravelsManager, self).get_query_set().filter(user=user)
class Travels(models.Model, ClonableMixin):
user = models.ForeignKey(User)
vehicle = models.ForeignKey(TravelsCars)
...
objects = UserTravelsManager()
它不会自己工作。我得到所有用户的所有汽车。我试过了:
return super(UserTravelsManager, self).get_query_set().filter(user=user, vehicle__user=user)
这也行不通。
更新:只是为了清除条目Travels
被过滤。如果我TravelsCars
通过Travels
.
我究竟做错了什么?