Opened 15 years ago

Closed 15 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().

Change History (1)

comment:1 by Russell Keith-Magee, 15 years ago

Resolution: duplicate
Status: newclosed

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.

Note: See TracTickets for help on using tickets.
Back to Top