Example #1
0
 def unread(self):
     if 'bikeanjo' in self.core_filters:
         return self.filter(
             bikeanjo_access__lt=models.F('helpreply__created_date'))
     elif 'requester' in self.core_filters:
         return self.filter(
             requester_access__lt=models.F('helpreply__created_date'))
     return self.none()
Example #2
0
    def with_rank(self):
        ranked = UrbanInstituteRentalCrisisData.objects.annotate(
            rank=models.Window(expression=Rank(),
                               partition_by=[models.F('year')],
                               order_by=(models.F('aaa_units') /
                                         models.F('eli_renters')).desc()),
            total=models.Window(expression=models.Count(['year']),
                                partition_by=[models.F('year')]))

        return ranked
 def get_aggregates(self):
     aggs = Drug.objects.filter(pk=self.pk).aggregate(
         sum_patients=models.Sum(
             'observationalstudy__patient_count'),
         sum_doctors=models.Sum(
             'observationalstudy__doc_count'),
         total_fee=models.Sum(
             models.F('observationalstudy__patient_count') *
             models.F('observationalstudy__fee_per_patient'),
             output_field=models.DecimalField(decimal_places=2,
                                              max_digits=19)
         )
     )
     return aggs
 def get_top_doctors(self, origin=None):
     qs = super(PaymentRecipientManager, self).get_queryset()
     qs = qs.filter(kind=0)
     if origin is None:
         qs = qs.annotate(
             total_amount=models.F('total_euro'),
             total_amount_currency='EUR'
         )
     else:
         qs = qs.filter(origin=origin)
         qs = qs.annotate(
             total_amount=models.F('total'),
             total_amount_currency=models.F('total_currency')
         )
     return qs.order_by('-total_amount')
Example #5
0
    def get_queryset(self):
        """Annotate queryset with an alias field 'name'.

        We want to test whether this annotation has been run after
        calling baker.make().
        """
        return super(MovieManager, self).get_queryset().annotate(name=models.F("title"))
Example #6
0
 def with_stats(self):
     return self.annotate(
         viewpoints_total=models.Count("viewpoints", distinct=True),
         pictures_submited=models.Count(
             "pictures__pk",
             filter=models.Q(pictures__state=Picture.SUBMITTED),
             distinct=True,
         ),
         pictures_accepted=models.Count(
             "pictures__pk",
             filter=models.Q(pictures__state=Picture.ACCEPTED),
             distinct=True,
         ),
         pictures_missing=models.F("viewpoints_total")
         - models.F("pictures_submited")
         - models.F("pictures_accepted"),
     )
Example #7
0
    def get_queryset(self):
        '''Annotate queryset with an alias field 'name'.

        We want to test whether this annotation has been run after
        calling mommy.make().

        '''
        return (
            super(MovieManager, self).get_queryset()
            .annotate(name=models.F('title'))
        )
    def update_last_locations(cls):
        """
        Update (if needed) delayed last location of all vehicles that aren't up to date.

        If location delay is enabled this needs to be called periodically to
        get locations actually updated in the API.
        """
        vehicles_with_new_locations = cls.objects.annotate(
            latest_timestamp=models.Max('locations__timestamp')).exclude(
                last_location__timestamp=models.F('latest_timestamp'))
        for vehicle in vehicles_with_new_locations:
            vehicle.update_last_location()
Example #9
0
 def with_rank(self):
     ranked = HudPitData.objects.annotate(
         rank=models.Window(expression=Rank(),
                            partition_by=[
                                models.F('datatype'),
                                models.F('geography'),
                                models.F('year')
                            ],
                            order_by=models.F('value').asc()),
         total=models.Window(expression=models.Count(
             ['datatype', 'geography', 'year']),
                             partition_by=[
                                 models.F('datatype'),
                                 models.F('geography'),
                                 models.F('year')
                             ]))
     return ranked
 def add_annotations(self, queryset):
     return queryset.annotate(
         payments_total=models.F('total'),
         payments_total_currency=models.F('total_currency')
     )
Example #11
0
 def with_rank(self):
     ranked = JCHSData.objects.exclude(datapoint='United States').annotate(
         asc_rank=models.Window(expression=Rank(),
                                partition_by=[
                                    models.F('datatype'),
                                    models.F('source'),
                                    models.F('date')
                                ],
                                order_by=models.F('value').asc()),
         desc_rank=models.Window(expression=Rank(),
                                 partition_by=[
                                     models.F('datatype'),
                                     models.F('source'),
                                     models.F('date')
                                 ],
                                 order_by=models.F('value').desc()),
         total=models.Window(expression=models.Count(
             ['datatype', 'source', 'date']),
                             partition_by=[
                                 models.F('datatype'),
                                 models.F('source'),
                                 models.F('date')
                             ]))
     return ranked