title: Filtering out duplicate and none values from Django queryset
body: <p>In a Django app, I can access user sessions and then get users_ids with <code>flat=True</code>. E.g. I'm doing:</p>
  
  <pre><code>Session.objects.filter(last_activity_gte=time_window).values_list('user_id',flat=True)
  </code></pre>
  
  <p>But the result is tainted by duplicates and <code>None</code> values. How do I perform the same query and filter out None or duplicates?</p>
  
  <p>One way to do this is:</p>
  
  <pre><code>time_window = timezone.now() - timedelta(minutes=5)
  user_ids = Session.objects.filter(last_activity_gte=time_window).values_list('user_id',flat=True)
  user_ids = [id for id in user_ids if id is not None]
  user_ids = set(user_ids)
  </code></pre>
  
  <p>But I wonder if I could have achieved that directly while querying the DB, which would be faster. Performance is crucial. </p>
  
  <hr>
  
  <p>If anyone's interested, I'm using <a href="https://github.com/Bouke/django-user-sessions" rel="nofollow">https://github.com/Bouke/django-user-sessions</a> to be able to access Django session objects as ORM objects</p>