In this document http://docs.djangoproject.com/en/dev/ref/contrib/admin/
 ModelAdmin.search_fields is explained:

"You can also perform a related lookup on a ForeignKey with the lookup
API "follow" notation.

search_fields = ['foreign_key__related_fieldname']"

I tried

search_fields = ['school__lawyer']

but I get an error message when I did a search for last name of
lawyer:

Related Field has invalid lookup: icontains

When I try

search_fields = ['school__last']

I get the error message

Cannot resolve keyword 'last' into field. Choices are: id, lawyer,
school

Maybe I don't understand what "related_fieldname" is.

What is it?

This is my model:

class School(models.Model):
    school = models.CharField(max_length=200)
    def __unicode__(self):
        return self.school


class Lawyer(models.Model):
    first = models.CharField(max_length=20)
    initial = models.CharField(blank=True, max_length=2)
    last = models.CharField(max_length=20)
    year_graduated = models.IntegerField('Year graduated')
    school = models.CharField(max_length=200)
    school = models.ForeignKey(School)
    def __unicode__(self):
        return self.first

Thank you

On Nov 10, 7:35 pm, Kenneth Gonsalves <law...@au-kbc.org> wrote:
> On Wednesday 11 Nov 2009 5:51:00 am Zeynel wrote:> So I want to enter in the 
> search box "Lawyer1" and in the result page
> > I want to see "Lawyer1 knows Lawyer2"
>
> if your school is a foreign key (I think it is) you need a related name to
> search for that. Check out ModelAdmin.search_fields in the docs. Not sure that
> this is what you are looking for though.
> --
> regards
> Kenneth Gonsalves
> Senior Project Officer
> NRC-FOSShttp://nrcfosshelpline.in/web/
--~--~---------~--~----~------------~-------~--~----~
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