我们从Python开源项目中,提取了以下9个代码示例,用于说明如何使用django.db.models.aggregates.Min()。
def range_statistics(start, end): """ Returns the statistics (totals) for a target date. Its month will be used. """ return DayStatistics.objects.filter(day__gte=start, day__lt=end).aggregate( total_cost=Sum('total_cost'), electricity1=Sum('electricity1'), electricity1_cost=Sum('electricity1_cost'), electricity1_returned=Sum('electricity1_returned'), electricity2=Sum('electricity2'), electricity2_cost=Sum('electricity2_cost'), electricity2_returned=Sum('electricity2_returned'), electricity_merged=Sum(models.F('electricity1') + models.F('electricity2')), electricity_cost_merged=Sum(models.F('electricity1_cost') + models.F('electricity2_cost')), electricity_returned_merged=Sum(models.F('electricity1_returned') + models.F('electricity2_returned')), gas=Sum('gas'), gas_cost=Sum('gas_cost'), temperature_min=Min('lowest_temperature'), temperature_max=Max('highest_temperature'), temperature_avg=Avg('average_temperature'), )
def get(self, request): if request.user.is_authenticated(): histories = OnlineHistory.objects.filter(mac=request.user.username)\ .values('date').annotate(min_time=Min('time'), max_time=Max('time')).order_by("-date") return render(request, "index.html", locals()) else: verification_token = str(uuid.uuid4()) request.session["verification_token"] = verification_token return render(request, "authentication.html", locals())
def get(self, request): if request.user.has_perm("mobile_scanner.view_staffonlinehistory"): histories = OnlineHistory.objects.filter()\ .values('date', 'user__last_name', 'user__first_name').annotate(min_time=Min('time'), max_time=Max('time')).order_by("-date") return render(request, "staff.html", locals()) else: msg = "?????" return render(request, "msg.html", locals())
def get_fastest_laps_by_vehicle(self, vehicle): return Lap.objects.filter( session__setup_actual__track=self, participant__vehicle=vehicle, count_this_lap=True, participant__is_player=True, ).values( 'participant', 'participant__member__steam_user__display_name', 'participant__vehicle__name' ).annotate(fastest_lap_time=Min('lap_time')).order_by('fastest_lap_time')
def get_fastest_laps_by_vehicle_class(self, vehicle_class): return Lap.objects.filter( session__setup_actual__track=self, participant__vehicle__vehicle_class=vehicle_class, count_this_lap=True, participant__is_player=True, ).values( 'participant__name', 'participant__vehicle__name' ).annotate(fastest_lap_time=Min('lap_time')).order_by('fastest_lap_time')
def _best_in_stage_evaluation(self, field_name): return getattr(self, field_name) <= self.participant.lap_set.filter( **{ '{}__gt'.format(field_name): 0, 'session_stage': self.session_stage } ).aggregate(Min(field_name))['{}__min'.format(field_name)]
def deployment_date(self): min_datetime = self.sensors.aggregate(first_light=Min('activation_date')) return min_datetime['first_light']
def deployment_date(self): sampling_feature = self.sampling_feature min_datetime = sampling_feature.feature_actions.aggregate(first_light=Min('results__valid_datetime')) return min_datetime['first_light']
def started_at(self): return self.subtask_participants_inclusive_filter.filter(status=STATUS_ACCEPTED).aggregate( start_date=Min('activated_at'))['start_date']