6
覆盖Django管理中的默认查询集
我的一个模型有一个delete标志,该标志用于全局隐藏对象: class NondeletedManager(models.Manager): """Returns only objects which haven't been deleted""" def get_query_set(self): return super(NondeletedManager, self).get_query_set().exclude(deleted=True) class Conversation(BaseModel): ... deleted = models.BooleanField(default=False) objects = NondeletedManager() all_conversations = models.Manager() # includes deleted conversations 如何覆盖Django管理模块使用的默认查询集以包括已删除的对话?