On Wed, 2006-05-17 at 14:45 +0200, Guillermo Fernandez Castellanos
wrote:
> Hi,
> 
> I'm very new to Django, and I'm a bit overhelmed with doc, so I might
> have missed something. Thanks for redirecting me then :-)
> 
> I've this model (simplified):
> 
> class Department(models.Model):
>     name = models.CharField(maxlength=10,primary_key=True)
>     class Admin:
>         pass
> 
> class Job(models.Model):
>     name = models.CharField(maxlength=30,primary_key=True)
>     department = models.ForeignKey(Department)
>     class Admin:
>         pass
> 
> class Person(models.Model):
>     name = models.CharField(maxlength=30,primary_key=True)
>     job = models.ForeignKey(Job)
> 
>     def _get_branch(self):
>         return Job.objects.select_related().get(name=self.job.name).department
>     department = property(_get_department)
> 
>     class Admin:
>         list_display = ('name','job','department')
>         list_filter = ('job','department')
>         search_fields = ('name')
> 
> My problem is that 'department' in list_display works just great,
> while in list_filter in makes an error:
> Request Method:       GET
> Request URL:  http://127.0.0.1:8000/admin/unitmanager/unit/
> Exception Type:       FieldDoesNotExist
> Exception Value:      name=branch
> Exception Location:   c:\program
> files\python24\lib\site-packages\django-0.91-py2.4.egg\django\db\models\options.py
> in get_field, line 97
> 
> Why is there an error? Is there a way to do what I want?

This is kind of hidden, but it is in the documentation: list_display can
take functions (and also properties), whereas list_filter can only take
fields from your model. "Department" is not a field, it's essentially a
function call (disguised as an attribute reference).  The reason for
this is that the fields in list_filter are used directly in an SQL
statement used to query the database, so we cannot have Python code at
that level.

Regards,
Malcolm

> 
> Thanks,
> 
> G
> 
> > 
> 


--~--~---------~--~----~------------~-------~--~----~
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 [EMAIL PROTECTED]
For more options, visit this group at 
http://groups.google.com/group/django-users
-~----------~----~----~----~------~----~------~--~---

Reply via email to