class SampleModel(models.Model):
   date = models.DateField()
   value = models.IntegerField()

subquery = SampleModels.objects.filter(
    date__gte=models.OuterRef('date') - timedelta(days=2),
    date__lte=models.OuterRef('date') + timedelta(days=2),
queryset = SampleModel.objects.annotate(

According to the documentation on OuterRef 

Use OuterRef when a queryset in a Subquery needs to refer to a field from 
> the outer query. It acts like an F 
> <>
>  expression 
> except that the check to see if it refers to a valid field isn’t made until 
> the outer queryset is resolved.

Since it states that it acts "like" an F expression, I assumed that 
utilizing a timedelta would be permissible. However, I receive the 
following traceback:

AttributeError: 'ResolvedOuterRef' object has no attribute 'relabeled_clone'

 I was able to find someone else that is having this problem on 
I would like to confirm whether this is a bug or a lack of clarification in 
the documentation. F expressions allow operations such as timedelta on 

Thanks for your help/advice in advance!

You received this message because you are subscribed to the Google Groups 
"Django users" group.
To unsubscribe from this group and stop receiving emails from it, send an email 
To post to this group, send email to
Visit this group at
To view this discussion on the web visit
For more options, visit

Reply via email to