Code

Opened 4 years ago

Closed 4 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:

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

Attachments (0)

Change History (1)

comment:1 Changed 4 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.

Add Comment

Modify Ticket

Change Properties
<Author field>
Action
as closed
as The resolution will be set. Next status will be 'closed'
The resolution will be deleted. Next status will be 'new'
Author


E-mail address and user name can be saved in the Preferences.

 
Note: See TracTickets for help on using tickets.