Opened 6 years ago

Closed 6 years ago

#12862 closed (duplicate)

Feature Request: Allow model @property methods to be serialized.

Reported by: orokusaki 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: UI/UX:


Let's say I have this class:

class Cart(models.Model):
    account = models.ForeignKey(Account)
    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 Changed 6 years ago by russellm

  • Needs documentation unset
  • Needs tests unset
  • Patch needs improvement unset
  • Resolution set to duplicate
  • Status changed from new to closed

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