Display objects related current user django admin
<p>I'm trying to display only objects related to the current user. Users can upload a file and then they can only see their files in the admin. Here is my models :</p>

<pre><code>class Share(models.Model):
    owner = models.ForeignKey(User, default='')
    title = models.CharField("File's title", max_length=100, unique=True, default='File')
    zip_file = models.FileField('Shared File', upload_to=content_zip_name, validators= [validation_zip])
</code></pre>

<p>and my admin.py</p>

<pre><code>from django.contrib import admin
from share.models import Share

class ShareAdmin(admin.ModelAdmin):
    list_display = ('title',)
    save_as = True

    def queryset(self, request):
        qs = super(ShareAdmin, self).queryset(request)
        if request.user.is_superuser:
            return qs
        return qs.filter(owner=request.user)

admin.site.register(Share, ShareAdmin)
</code></pre>

<p>I tried with overriding the queryset function but doesn't work..any idea? </p>

<p>You've confused the <a href="https://docs.djangoproject.com/en/1.10/ref/contrib/admin/#django.contrib.admin.ModelAdmin.list_filter" rel="nofollow"><code>queryset</code></a> method  (used with <code>list_filter</code>)  with the <a href="https://docs.djangoproject.com/en/1.10/ref/contrib/admin/#django.contrib.admin.ModelAdmin.get_queryset" rel="nofollow"><code>get_queryset</code></a> method:</p>

<blockquote>
  <p>The <code>get_queryset</code> method on a <code>ModelAdmin</code> returns a <em>QuerySet</em> of all
  model instances that can be edited by the admin site. One use case for
  overriding this method is to show objects owned by the <strong>logged-in</strong>
  user.</p>
</blockquote>

<p>[<em>Emphasis mine</em>]</p>

<pre><code>class ShareAdmin(admin.ModelAdmin):
    list_display = ('title',)
    save_as = True

    def get_queryset(self, request):
        qs = super(ShareAdmin, self).get_queryset(request)
        if request.user.is_superuser:
            return qs
        return qs.filter(owner=request.user)
</code></pre>

python django django-queryset