title: Django difficulty using ModelAdmin.queryset with ModelAdmin.list_filter to limit the filter itrems displayed
body: <p>In Django 1.5.1 I setup a SAAS system for internal use, where each department gets their own set of data.</p>
  
  <p>To do that, I use <strong>ModelAdmin.queryset</strong> (<a href="https://docs.djangoproject.com/en/1.5/ref/contrib/admin/#django.contrib.admin.ModelAdmin.queryset" rel="nofollow">https://docs.djangoproject.com/en/1.5/ref/contrib/admin/#django.contrib.admin.ModelAdmin.queryset</a>) to limit all data to only the records that <em>belong</em> to the department of the currently logged in user.</p>
  
  <p>This works perfect for the main Admin functions (summary tables etc.).  But anything I put on <strong>"ModelAdmin.list_filter"</strong> shows ALL values - obviously using the base query set and not the one I defined in <strong>ModelAdmin.queryset</strong>.</p>
  
  <p>I can see how one can define a custom <strong>ModelAdmin.list_filter</strong> query here: <a href="https://docs.djangoproject.com/en/1.5/ref/contrib/admin/#django.contrib.admin.ModelAdmin.list_filter" rel="nofollow">https://docs.djangoproject.com/en/1.5/ref/contrib/admin/#django.contrib.admin.ModelAdmin.list_filter</a> that lets you also define a custom filter manager, which can include a custom queryset.</p>
  
  <p>But this is <strong><em>PER FILTER FIELD!</em></strong></p>
  
  <p>That seems like an awful lot of work for something that should be automatic once you add <strong>ModelAdmin.queryset</strong>!</p>
  
  <p>Is there a simpler way I'm missing here, or maybe this is something I should ticket?</p>
  
  <p>Thanks in advance,</p>
  
  <p>Rich.</p>
  
  <p><strong><em>Peter, thanks for the kick in my pants.  Turns out my understanding of my own problem was wrong!</em></strong></p>
  
  <p>================= Example from my code ================</p>
  
  <pre><code>class Company(models.Model):
      """Company model."""
      accountid = models.CharField(_('Account Number'), max_length=20, null=False, blank=True, help_text="Link to old system and records")
      name = models.CharField(_('name'), max_length=200, unique=True, help_text=_("Enter full company name, no abbreviations. Duplicates are not allowed."))
      nickname = models.CharField(_('nickname'), max_length=50, blank=True, null=True, help_text=_("Enter one or more keywords or abbreviations seperated by a space to make searching easier"))
      slug = AutoSlugField(_('slug'), max_length=50, unique=True, blank=False, populate_from=('name', ))
      site = models.ForeignKey(Site, default="0", blank=False, null=False, editable=False, help_text="Indicate which site this record belongs to. ")
  
  
  class CompanyAdmin(admin.ModelAdmin):
      list_filter = ('type', 'lead_quality', )
  
      def queryset(self, request):
          qs = super(PersonAdmin, self).queryset(request)
          if request.user.is_superuser:
              self.message_user(request, "Warning: This is the ADMINISTRATOR view!!", 'warning')
              return qs
          return qs.filter(site__id=request.session['site'].id)
  
      def save_model(self, request, obj, form, change):
          if change:
              if obj.site.id != request.session['site'].id:
                  logger.debug("Contacts.Person.save_model: replacing site (%s) with (%s) " % (repr(obj.site), repr(request.session['site'])) )
          else:
              logger.debug("Contacts.Person.save_model: setting site (%s)" % (repr(request.session['site'])) )
          obj.site = request.session['site']
          obj.save()
  
  
  class Person(models.Model):
      """Person model."""
      first_name = models.CharField(_('first name'), max_length=100)
      last_name = models.CharField(_('last name'), max_length=200)
      slug = AutoSlugField(_('slug'), max_length=50, unique=True, blank=False, populate_from=('first_name', 'last_name'))
      company = models.ForeignKey(Company, blank=True, null=True, help_text=_("If this person is associated with a Company, indicate which one here.") )
      site = models.ForeignKey(Site, default="0", blank=False, null=False, editable=False, help_text="Indicate which site this record belongs to. ")
  
  
  class PersonAdmin(admin.ModelAdmin):
      list_filter = ('company',)
  
      def queryset(self, request):
          qs = super(PersonAdmin, self).queryset(request)
          if request.user.is_superuser:
              self.message_user(request, "Warning: This is the ADMINISTRATOR view!!", 'warning')
              return qs
          return qs.filter(site__id=request.session['site'].id)
  
      def save_model(self, request, obj, form, change):
          if change:
              if obj.site.id != request.session['site'].id:
                  logger.debug("Contacts.Person.save_model: replacing site (%s) with (%s) " % (repr(obj.site), repr(request.session['site'])) )
          else:
              logger.debug("Contacts.Person.save_model: setting site (%s)" % (repr(request.session['site'])) )
          obj.site = request.session['site']
          obj.save()
  
      def formfield_for_foreignkey(self, db_field, request, **kwargs):
          if db_field.name in ('company',):
              kwargs["queryset"] = Company.objects.get_query_set().filter(site__id=request.session['site'].id)
          return super(PersonAdmin, self).formfield_for_foreignkey(db_field, request, **kwargs)
  </code></pre>
  
  <p>So when a User views the summary screen for <strong>People</strong>, and they click on the Filter for <strong>Company</strong>, they see choices belonging to other company divisions.</p>
  
  <p>If they click on one belonging to another division they get an empty list since the PersonAdmin cannot actually access that record.</p>