Opened 17 years ago
Closed 17 years ago
#6876 closed (duplicate)
Allow serialization of model methods
Reported by: | Marc Garcia | Owned by: | nobody |
---|---|---|---|
Component: | Core (Serialization) | Version: | dev |
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: | no | UI/UX: | no |
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.
Note:
See TracTickets
for help on using tickets.
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.