On 11/23/12 15:31, Aaron C. de Bruyn wrote:
> Python 2.7.3 (default, Aug  1 2012, 05:14:39) 
> [GCC 4.6.3] on linux2
> Type "help", "copyright", "credits" or "license" for more information.
> (InteractiveConsole)
>>>> u = User.objects.get(pk=1)
>>>> u.user = 'test'
>>>>
> 
> No error.  It should be 'u.username'.

This is a Python thing, not limited to Django, and fully expected:

Python 2.6.6 (r266:84292, Dec 26 2010, 22:31:48)
[GCC 4.4.5] on linux2
Type "help", "copyright", "credits" or "license" for more information.
>>> class MyClass(object): pass
...
>>> c = MyClass()
>>> c.doesnotexist = 42

Barring some particular situations (you may want to read up on
__slots__), you can dynamically add any property you want to an
object/class.  Python is less forgiving if you *read* nonexistent
properties:

>>> print c.no_property_here
Traceback (most recent call last):
  File "<stdin>", line 1, in <module>
AttributeError: 'MyClass' object has no attribute 'no_property_here'


-tkc







-- 
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