From: Luke Plant <L.Plant...@cantab.net>
Date: Tue, 17 May 2011 19:35:24 +0100
Local: Tues, May 17 2011 2:35 pm
Subject: Re: list_display does not allow foreign keys __ syntax
Hi Anshuman,
On 17/05/11 14:42, Anshuman Aggarwal wrote: > list_display OK, back to basics: > allows for callables and hence arbitrary names can be used which are > similar to the syntax for foreign key fields. > However, this problem exists for list_filter also: someone may define > a > field with the name class__field and try to use that in list_filter as > a > foreign key field. (i've just checked that you can indeed name a field > like that) > So we can't really be compensating for dev stupidity at the cost of ModelAdmin.list_display answers this question: 1) Given a Python object that is a Model instance, what pieces of It answers the question in this way: We display string representations of A) attributes of the instance, However, once you've answered that question, you've got another: 2) Given only a ModelAdmin and/or Model class, how can we define The answer to this is harder, because in general we can't. However, we A) if the piece of information is an attribute that is a field on the This is a very good guess, because we can be pretty sure that the B) if the attribute is '__str__', use the verbose_name of the Model Failing this: C) Just turn 'some_attribute' into 'Some attribute' and then: D) Allow complete customisation via the 'short_description' Given this is what list_display is about, the suggestion of supporting 'some_obj.some_field' Using '__' only makes sense for answering question 2, and only for case Then comes the question - should we support the dot syntax? This is We will either have to - duplicate some of the logic from the ORM about traversing fields, - OR put logic into the core ORM that is there to support this (This applies whether we use '__' or '.' syntax). Both of these are big code smells. Secondly, we also have a question of what we do this the field class Place(Model): class Person(Model): class Department(Model): And then: class DepartmentAdmin(ModelAdmin): What should the display columns be called? I think I would want: Name | Manager | Manager level | Location | Country 3 different rules would be required to satisfy all these, and all rules The success rate for this kind of guessing can't be much better than I could just about see a case for supporting the dotted syntax and not Best regards, Luke -- Luke Plant || http://lukeplant.me.uk/ You must Sign in before you can post messages.
To post a message you must first join this group.
Please update your nickname on the subscription settings page before posting.
You do not have the permission required to post.
| ||||||||||||||