Question

I want to filter my queryset as below

Post.objects.select_related().filter(dt_published__range=[post_start_date, now])

for the post_start_date, I would like to use

user_start_date = User.objects.filter(username=request.user).values_list('date_joined')

and go 7 days back from there

I can't do

post_start_date = user_start_date - timedelta(days=7) 

because the result of user_start_date gives me output as this

[(datetime.datetime(2014, 1, 19, 16, 55, 29, 27064),)]

any idea how can I change the output of user_start_date so I can manipulate the date ?

thanks -s

Was it helpful?

Solution

You can get the user_start_date without using values_list. Please try this:

# request.user is already a User object
user_start_date = request.user.date_joined

# Now this should work
post_start_date = user_start_date - timedelta(days=7) 
Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top