Opened 10 years ago

Closed 10 years ago

#6876 closed (duplicate)

Allow serialization of model methods

Reported by: Marc Garcia 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:


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.

Change History (1)

comment:1 Changed 10 years ago by Russell Keith-Magee

Resolution: duplicate
Status: newclosed

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.

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