Hi

This seems a very complicated solution to a fairly basic problem unless I
am missing something

> On Feb 7, 2014 2:24 AM, "fborell" <frankbor...@gmail.com> wrote:
> 
> > I need to create a second application in the admin section that ports
> > to the first applications model. The second application's admin.py
> > would contain only 5 of the 15 fields and be set for read-only.
> > My goal was to allow certain users the ability to do a simple search
> > and not see some of the other data that they weren't authorized for.
> >
> > Any thoughts on how to proceed?

Create a regular ListView only showing the fields you want and then add an
ordinary form field to the template to input your search term (I would
usually include it with pagination controls)

In your view you can then filter the queryset on the search term like this

#views.py
  def get_queryset(self):
    qs = super(MyListView, self).get_queryset()
    if 'SEARCH' in self.request.GET:
      search = self.request.GET['SEARCH']
      qs =
      qs.filter(Q(field1__icontains=search)|Q(field2__icontains=search)) 
    return qs

There is more on "Complex lookups with Q objects" in

https://docs.djangoproject.com/en/1.6/topics/db/queries/

-- 
Drew

-- 
You received this message because you are subscribed to the Google Groups 
"Django users" group.
To unsubscribe from this group and stop receiving emails from it, send an email 
to django-users+unsubscr...@googlegroups.com.
To post to this group, send email to django-users@googlegroups.com.
Visit this group at http://groups.google.com/group/django-users.
To view this discussion on the web visit 
https://groups.google.com/d/msgid/django-users/20140207015103.6ba1b05b%40blacktav.fergiesontour.org.
For more options, visit https://groups.google.com/groups/opt_out.

Reply via email to