How to calculate user age from birth year till registration date using Django ORM
<p>i have a model which contains a field birth_year and in another model i have the user registration date.
I have the list of user ids for which i want to query if their age belongs to a particular range of age.User age is calculated as registration date - birth_year.</p>

<p>I was able to calculate it from current date as:</p>

<pre><code>startAge=25
endAge=50
ageStartRange = (today - relativedelta(years=startAge)).year
ageEndRange = (today - relativedelta(years=endAge)).year
</code></pre>

<p>and i made the query as:</p>

<pre><code>query.filter(profile_id__in=communityUsersIds, birth_year__lte=age_from, birth_year__gte=age_to).values('profile_id')
</code></pre>

<p>This way i am getting the userids whose age is in range bw 25 and 50. Instead of today how can i use registration_date(it is a field in another model) of user.</p>