On Wed, 2007-11-14 at 10:15 +0100, Jens Diemer wrote:
> 
> I would like to escape the data from a model attribute...
> 
> Here a example:
> 
> 
> 
> Old model:
> -------------------------------------------------------------
> class Page(models.Model):
>      ...
>      name = models.CharField()
>      ...
> -------------------------------------------------------------
> 
> 
> I have changed the model to this:
> -------------------------------------------------------------
> class Page(models.Model):
>      ...
>      __name = models.CharField(
>          db_column='name'
>      )
>      def __get_name(self):
>          return escape(self.__name)
> 
>      def __set_name(self, data):
>          self.__name = data
> 
>      name = property(__get_name, __set_name)
>      ...
> -------------------------------------------------------------
> 
> 
> 
> Now, i have a problem :(
> 
> This works, fine:
>       page = Page.objects.all()[0]
>       print page.name
> 
> 
> But here i get a 'FieldDoesNotExist' Traceback:
>       print Page.objects.values("name")
> 
[...]
> 
> Why?
> Is this a bug?

Everything is behaving normally. You just can't do what you're trying to
do. When the class is constructed (when the __new__ method is called),
Django doesn't know (and has no way of possibly knowing) that the "name"
property is simply a proxy for the "__name" Field object. And Django
does special initialisation processing for Field objects, including
creating a list of fields on the model.

So, when you are trying to use your field in a queryset, you must refer
to it using it's true name ("__name" in your case).

Malcolm


-- 
Atheism is a non-prophet organization. 
http://www.pointy-stick.com/blog/


--~--~---------~--~----~------------~-------~--~----~
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?hl=en
-~----------~----~----~----~------~----~------~--~---

Reply via email to