本文整理匯總了Python中jsonfield.JSONField方法的典型用法代碼示例。如果您正苦於以下問題:Python jsonfield.JSONField方法的具體用法?Python jsonfield.JSONField怎麽用?Python jsonfield.JSONField使用的例子?那麽, 這裏精選的方法代碼示例或許可以為您提供幫助。您也可以進一步了解該方法所在類jsonfield
的用法示例。
在下文中一共展示了jsonfield.JSONField方法的1個代碼示例,這些例子默認根據受歡迎程度排序。您可以為喜歡或者感覺有用的代碼點讚,您的評價將有助於係統推薦出更棒的Python代碼示例。
示例1: optimize_queryset_for_list
# 需要導入模塊: import jsonfield [as 別名]
# 或者: from jsonfield import JSONField [as 別名]
def optimize_queryset_for_list(queryset):
""" Used by serializers to improve performance when listing assets """
queryset = queryset.defer(
# Avoid pulling these `JSONField`s from the database because:
# * they are stored as plain text, and just deserializing them
# to Python objects is CPU-intensive;
# * they are often huge;
# * we don't need them for list views.
'content', 'report_styles'
).select_related(
# We only need `username`, but `select_related('owner__username')`
# actually pulled in the entire `auth_user` table under Django 1.8.
# In Django 1.9+, "select_related() prohibits non-relational fields
# for nested relations."
'owner',
).prefetch_related(
# We previously prefetched `permissions__content_object`, but that
# actually pulled the entirety of each permission's linked asset
# from the database! For now, the solution is to remove
# `content_object` here *and* from
# `ObjectPermissionNestedSerializer`.
'permissions__permission',
'permissions__user',
# `Prefetch(..., to_attr='prefetched_list')` stores the prefetched
# related objects in a list (`prefetched_list`) that we can use in
# other methods to avoid additional queries; see:
# https://docs.djangoproject.com/en/1.8/ref/models/querysets/#prefetch-objects
Prefetch('tags', to_attr='prefetched_tags'),
Prefetch(
'asset_versions',
queryset=AssetVersion.objects.order_by(
'-date_modified'
).only('uid', 'asset', 'date_modified', 'deployed'),
to_attr='prefetched_latest_versions',
),
)
return queryset