- Django 3.2 中的新函數。
字段名稱的可選字符串(帶有表示降序的可選
"-"
前綴)或指定結果列表中元素順序的表達式(或元組或字符串和/或表達式列表)。示例與
ArrayAgg.ordering
本文介紹django.contrib.postgres.aggregates.JSONBAgg.ordering
的用法。
聲明
ordering
使用示例:
class Room(models.Model):
number = models.IntegerField(unique=True)
class HotelReservation(model.Model):
room = models.ForeignKey('Room', on_delete=models.CASCADE)
start = models.DateTimeField()
end = models.DateTimeField()
requirements = models.JSONField(blank=True, null=True)
>>> from django.contrib.postgres.aggregates import JSONBAgg
>>> Room.objects.annotate(
... requirements=JSONBAgg(
... 'hotelreservation__requirements',
... ordering='-hotelreservation__start',
... )
... ).filter(requirements__0__sea_view=True).values('number', 'requirements')
<QuerySet [{'number': 102, 'requirements': [
{'parking': False, 'sea_view': True, 'double_bed': False},
{'parking': True, 'double_bed': True}
]}]>
自 4.0 版以來已棄用:如果沒有行並且default
未提供,JSONBAgg
返回一個空列表而不是None
.此行為已棄用,將在 Django 5.0 中刪除。如果需要,請顯式設置default
到Value('[]')
.
相關用法
- Python Django JSONCatalog用法及代碼示例
- Python JSON轉CSV用法及代碼示例
- Python JSON轉string用法及代碼示例
- Python Django JSONObject用法及代碼示例
- Python Django JSONSerializer用法及代碼示例
- Python JSON轉dictionary用法及代碼示例
- Python Django JavaScriptCatalog.packages用法及代碼示例
- Python cudf.core.column.string.StringMethods.is_vowel用法及代碼示例
- Python torch.distributed.rpc.rpc_async用法及代碼示例
- Python torch.nn.InstanceNorm3d用法及代碼示例
- Python sklearn.cluster.MiniBatchKMeans用法及代碼示例
- Python pandas.arrays.IntervalArray.is_empty用法及代碼示例
- Python tf.compat.v1.distributions.Multinomial.stddev用法及代碼示例
- Python numpy.less()用法及代碼示例
- Python Matplotlib.figure.Figure.add_gridspec()用法及代碼示例
- Python tf.compat.v1.distribute.MirroredStrategy.experimental_distribute_dataset用法及代碼示例
- Python Django File.save用法及代碼示例
- Python Sympy Permutation.list()用法及代碼示例
- Python dask.dataframe.Series.apply用法及代碼示例
- Python networkx.algorithms.shortest_paths.weighted.all_pairs_dijkstra_path用法及代碼示例
- Python scipy.ndimage.binary_opening用法及代碼示例
- Python pyspark.pandas.Series.dropna用法及代碼示例
- Python torchaudio.transforms.Fade用法及代碼示例
- Python dask.dataframe.to_records用法及代碼示例
- Python arcgis.gis._impl._profile.ProfileManager.save_as用法及代碼示例
注:本文由純淨天空篩選整理自djangoproject.com大神的英文原創作品 django.contrib.postgres.aggregates.JSONBAgg.ordering。非經特殊聲明,原始代碼版權歸原作者所有,本譯文未經允許或授權,請勿轉載或複製。