Code

Opened 6 years ago

Closed 6 years ago

#6876 closed (duplicate)

Allow serialization of model methods

Reported by: garcia_marc Owned by: nobody
Component: Core (Serialization) Version: master
Severity: Keywords: serialization model method calculated field
Cc: marc.garcia@… Triage Stage: Unreviewed
Has patch: no Needs documentation: no
Needs tests: no Patch needs improvement: no
Easy pickings: UI/UX:

Description

It will be useful if model methods could be serialized. For example:

in model...

class Person(models.Model):
    first_name = models.CharField(max_length=32)
    family_name = models.CharField(max_length=32)

    def full_name(self):
        return '%s %s' % (self.first_name, self.family_name)

...when serializing...

data = serializers.serialize('json', Person.objects.all())

...doesn't include full_name, even if specified in fields.

Attachments (0)

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

Serializing methods isn't really possible in the generic sense, since a method could require arguments. However, serialization of properties (which can be implemented as methods), and serialization of any other model property has been accepted as a proposal - see ticket #5711.

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.