Python django.db.models.aggregates.Min() Examples
The following are code examples for showing how to use django.db.models.aggregates.Min(). They are extracted from open source Python projects. You can vote up the examples you like or vote down the ones you don't like. You can also save this page to your account.
Example 1
Project: dsmr-reader Author: dennissiemensma File: services.py (license) View Source Project | 6 votes |
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'), )
Example 2
Project: wifi-attendance Author: elvinzeng File: views.py (license) View Source Project | 5 votes |
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())
Example 3
Project: wifi-attendance Author: elvinzeng File: views.py (license) View Source Project | 5 votes |
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())
Example 4
Project: autostew Author: Autostew File: models.py (license) View Source Project | 5 votes |
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')
Example 5
Project: autostew Author: Autostew File: models.py (license) View Source Project | 5 votes |
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')
Example 6
Project: autostew Author: Autostew File: models.py (license) View Source Project | 5 votes |
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)]
Example 7
Project: ODM2WebSDL Author: ODM2 File: models.py (license) View Source Project | 5 votes |
def deployment_date(self): min_datetime = self.sensors.aggregate(first_light=Min('activation_date')) return min_datetime['first_light']
Example 8
Project: ODM2WebSDL Author: ODM2 File: models.py (license) View Source Project | 5 votes |
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']
Example 9
Project: tunga-api Author: tunga-io File: models.py (license) View Source Project | 5 votes |
def started_at(self): return self.subtask_participants_inclusive_filter.filter(status=STATUS_ACCEPTED).aggregate( start_date=Min('activated_at'))['start_date']