table_post = Post._meta.db_table
table_plan = Plan._meta.db_table
old_posts = Post.objects.select_related('plan').extra(where=[
    "%s.created_at <= NOW() - INTERVAL '1 day' * %s.days" % (table_post,
    table_plan)])
Django - Filter objects older than X days