django - 筛选相关模型django

标签 django django-queryset

如何通过相关模型生成query_set?

例如,如何执行此操作:

UserProfile.objects.filter(user.is_active=True) # Can't use user.is_active to filter

琐碎的问题,琐碎的答案。但是为了后代的缘故,我将其保留在这里。

最佳答案

UserProfile.objects.filter(user__is_active=True) 

Django文档中的documented很好。

关于django - 筛选相关模型django,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/7339580/

相关文章:

python - 启用 AUTHENTICATION_BACKENDS 后 Django.contrib.auth 单元测试失败

Django 查询集附加或注释相关对象字段

python - Django 查询给定位置的有序对象

Django 在属性字段上进行注释

sql - 在 Django 中对 ValuesQuerySet 使用 extra()

mysql - 列 QuerySet API (Django) 的最后一个值

python - Django:按 child 的属性排序对象

python - 由 <function check_errors.<locals>.wrapper at 0x10deb92f0> 启动的线程中出现未处理的异常

Django makemigrations 应用程序顺序

python - 为什么 django.forms.CharField 中缺少 "blank",但存在于 django.db.models.CharField 中?