Opened 16 years ago
Closed 16 years ago
#12862 closed (duplicate)
Feature Request: Allow model @property methods to be serialized.
| Reported by: | Oroku Saki | Owned by: | nobody |
|---|---|---|---|
| Component: | Uncategorized | Version: | 1.1 |
| Severity: | Keywords: | ||
| Cc: | Triage Stage: | Unreviewed | |
| Has patch: | no | Needs documentation: | no |
| Needs tests: | no | Patch needs improvement: | no |
| Easy pickings: | no | UI/UX: | no |
Description
Let's say I have this class:
class Cart(models.Model):
account = models.ForeignKey(Account)
@property
def total(self):
total = 0
for item in self.item_set:
total += item.price
return total
Obviously if I were to serialize this model, I would want the total to be serialized. I wouldn't mind having to include it in fields=() argument of serialize().
Note:
See TracTickets
for help on using tickets.
I'm going to call this a duplicate of #5711; that ticket talks about extra() specifically, but the ticket discussion raises the issue of serializing arbitrary properties on a model.