Saturday, August 18, 2012

Re: Django Admin doesn't show all fields from model when registered.



Le jeudi 16 août 2012 21:00:56 UTC+2, Tundebabzy a écrit :
Ok I fixed it and in case someone else falls into such a trap, here's
how I fixed it.

My Answer model had a field with name 'is_correct' and had a method
with name 'is_correct'.


Everything in Python is an object, including functions, classes, modules etc. In a class statement's body, if you first bind name "is_correct" to something (here a field but it could have been anything) then to something else (here a function but it could have been anything too), then the second binding will replace the first one.

 

I think django should be able to detect such things and raise an error

"Django" (that is, in this case, django models metaclass) doesn't even know about this - all it gets is the namespace (ie: a dict) obtained by evaluating the class statement's body. This is how Python work, and expecting something else just means that you assume it works like some other language you already know (bad luck: no two languages work the same).
 
or there should be a note in the documentation warning people not to
name their model methods with model field names.


Why should Django documents Python features ? Python is already (and quite extensively) documented on it's own : http://docs.python.org/



 

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

0 Comments:

Post a Comment

Subscribe to Post Comments [Atom]

<< Home


Real Estate