A feature I would really appreciate (as devs in
http://stackoverflow.com/questions/12217763/does-django-orm-have-an-equivalent-to-sqlalchemys-hybrid-attribute,
at least) is the Hybrid Property feature present in SQLAlchemy. They would
really contribute to DRY principle.
In django this would allow using it as a left-side for the key=value in a
filter query (in sqlalchemy they filter by <Class>.<property> as part of an
expression ). Example:
class Purchase(models.Model):
first_name = CharField(...)
last_name = CharField(...)
...
@hybrid_property
def full_name(self):
return self.first_name + ' ' + self.full_name
or ...
class ProductEntry(models.Model):
purchase = ForeignKey(Purchase, related_name='product_entries')
onpurchase_price = DecimalField(...)
product = ForeignKey(Product)
quantity = DecimalField(...)
...
@hybrid_property
def cost(self):
return self.onpurchase_price * self.quantity
... being those queries valid and working as expected
Person.objects.filter(full_name__ilike='Martin')
ProductEntry.objects.filter(cost__lt=5000.0) #SQLAlchemy would use
ProductEntry.cost < 5000.0
--
You received this message because you are subscribed to the Google Groups
"Django developers" group.
To unsubscribe from this group and stop receiving emails from it, send an email
to [email protected].
To post to this group, send email to [email protected].
Visit this group at http://groups.google.com/group/django-developers.
For more options, visit https://groups.google.com/groups/opt_out.