This is my simplified code:

# models.py
class Category(models.Model):
    user = models.ForeignKey(User)
    text = models.CharField(max_length=200)
    slug = models.SlugField(max_length=200, editable=False)

class Book(models.Model):
    isbn = models.CharField(max_length=32)
    title = models.CharField(max_length=255)
    categories = models.ManyToManyField(Category)


# admin.py

""" overwrite queryset in order the user only see books belongs to na
category belong to him, in chage_list view """

class BookAdmin(admin.ModelAdmin):
    list_display = ('isbn', 'title')
    search_fields = ['isbn','title']

    def queryset(self, request):
        user = request.user
        self.user = user
        if not user.is_superuser:
            qs = self.model._default_manager.get_query_set().filter
(category__user=user)
        else:
            qs = self.model._default_manager.get_query_set().all
()
        ordering = self.ordering or ()
        if ordering:
            qs = qs.order_by(*ordering)
        return qs

This all is ok. But when i go to the "book" detail page in admin site.
The "Category" Multiple Select box show all categories of all users,
not only the user's ones. What i'm looking for is the way i can filter
the choices list in that Multiple Select Box by user.

Thanks all

Gonzalo Salvador



On 1 oct, 11:29, Cousteau <j.coustea...@gmail.com> wrote:
> Hello:
>
> I'm trying to filter the choices in a Multiple select box in admin
> site, in order to show only those belongs to the user
>
> Is it posssible?

--~--~---------~--~----~------------~-------~--~----~
You received this message because you are subscribed to the Google Groups 
"Django users" group.
To post to this group, send email to django-users@googlegroups.com
To unsubscribe from this group, send email to 
django-users+unsubscr...@googlegroups.com
For more options, visit this group at 
http://groups.google.com/group/django-users?hl=en
-~----------~----~----~----~------~----~------~--~---

Reply via email to