Find centralized, trusted content and collaborate around the technologies you use most.
Teams
Q&A for work
Connect and share knowledge within a single location that is structured and easy to search.
我如何覆盖关系经理?例如:
user.entry_set # django.db.models.fields.related.RelatedManager
但我需要我自己的经理。我尝试了这段代码,但这不起作用:
class EntryManager(models.Manager): use_for_related_fields = True
谢谢。
您的任务需要相当复杂的代码,这将很难维护和理解(如果可能的话)。
那这个呢?
class EntryManager(models.Manager): def by_user(self, user): # do anything you want # usage Entry.objects.by_user(user=user)