title: Django admin add custom filter
body: <p>i'm using django 1.10 and I need to display data and create a filter based on a value from a different model(which has a foreign key referencing my model that is used on the admin template)
  These are my 2 models:
  This one is used to generate the template:</p>
  <pre><code>class Job(models.Model):
      company = models.ForeignKey(Company)
      title = models.CharField(max_length=100, blank=False)
      description = models.TextField(blank=False, default='')
      store = models.CharField(max_length=100, blank=True, default='')
      phone_number = models.CharField(max_length=60, null=True, blank=True)
  </code></pre>
  <p>This is the other one that holds a foreign key reference to my first one:</p>
  <pre><code>class JobAdDuration(models.Model):
      job = models.ForeignKey(Job)
      ad_activated = models.DateTimeField(auto_now_add=True)
      ad_finished = models.DateTimeField(blank=True, null=True)
  </code></pre>
  <p>Inside my template, I have been able to display the(latest)start and end times</p>
  <pre><code>def start_date(self,obj):
      if JobAdDuration.objects.filter(job=obj.id).exists():
          tempad = JobAdDuration.objects.filter(job=obj).order_by(&quot;-id&quot;)[0]
          return tempad.ad_activated
  </code></pre>
  <p>And then I just call this inside the list_display and that is working fine.
  However, i have trouble setting a filter field using these criteria.</p>
  <p>If I just add it to my list_filter then I get an error that there is no such field inside my model which is true (since that one is in another table that has reference to my job table). So I was wondering what is the right approach to solve this? Do I need to create another function for the filter itself but even then I'm not sure how should I call it inside the list_filter.</p>
  <p>Here is a snippet of my Django admin page.</p>
  <pre><code>class JobAdmin(admin.OSMGeoAdmin, ImportExportModelAdmin):
      inlines = [
      ]
  
      readonly_fields = ( 'id', &quot;start_date&quot;, )
  
      raw_id_fields = (&quot;company&quot;,)
  
      list_filter = (('JobAdDuration__ad_activated', DateRangeFilter), 'recruitment', 'active', 'deleted', 'position', ('created', DateRangeFilter), 'town')
      search_fields = ('title', 'description', 'company__name', 'id', 'phone_number', 'town')
      list_display = ('title', 'id', 'description', 'active', 'transaction_number', 'company', 'get_position', 'town','created', 'expires', 'views', 'recruitment', 'recruits', 'paid', 'deleted', &quot;start_date&quot;, &quot;end_Date&quot;, &quot;ad_consultant&quot;)
  
  
      def start_date(self,obj):
          if JobAdDuration.objects.filter(job=obj.id).exists():
              tempad = JobAdDuration.objects.filter(job=obj).order_by(&quot;-id&quot;)[0]
              return tempad.ad_activated
  </code></pre>
  <p>EDIT:
  In the meantime, I tried to solve it with a simple list filter, but I am unable to get it to work. I would like to place 2 input fields with a calendar(like the default DateRangeFilter) that would represent the start and end time, and then return data based on those values. This is my &quot;prototype&quot; functionality for the simple filter, it works but it returns hard-coded data.</p>
  <pre><code>class StartTimeFilter(SimpleListFilter):
      title = ('Start date')
      parameter_name = 'ad_finished'
  
      def lookups(self, request, model_admin):
         #return JobAdDuration.objects.values_list(&quot;ad_finished&quot;)
         return (
         ('startDate', 'stest1'),
         ('startDate1', 'test2')
         )
  
      def queryset(self, request, queryset):
          if not self.value():
              return queryset
  
   
          assigned = JobAdDuration.objects.filter(ad_finished__range=(datetime.now() - timedelta(minutes=45000), datetime.now()))
          allJobs = Job.objects.filter(pk__in=[current.job.id for current in assigned])
          return allJobs
  
   
  </code></pre>