Is there a way to combine python properties with Django fields so that
one can essentially use both regular (persistent) and callable fields
transparently ? If the previous sentence didn't make any sense, here's
a simplest example:
from django.db.models import Model, IntegerField
class Foo(Model):
number = IntegerField()
square = property(lambda self: self.number ** 2)
x = Foo(number=3)
# attribute access works transparently:
print x.number, x.square
# still you can't do something "for every field" and have square
# included
for field in Foo._meta.fields:
print "%s: %s" % (field.name, getattr(x,field.name)
Any ideas ?
--~--~---------~--~----~------------~-------~--~----~
You received this message because you are subscribed to the Google Groups
"Django users" group.
To post to this group, send email to [email protected]
To unsubscribe from this group, send email to [EMAIL PROTECTED]
For more options, visit this group at
http://groups.google.com/group/django-users
-~----------~----~----~----~------~----~------~--~---