PageRenderTime 4ms CodeModel.GetById 1ms app.highlight 1ms RepoModel.GetById 1ms app.codeStats 0ms

/tests/modeltests/properties/models.py

https://code.google.com/p/mango-py/
Python | 21 lines | 10 code | 6 blank | 5 comment | 0 complexity | 3305f33b37ae0ac8f4e0b13510806e2a MD5 | raw file
 1"""
 222. Using properties on models
 3
 4Use properties on models just like on any other Python object.
 5"""
 6
 7from django.db import models
 8
 9class Person(models.Model):
10    first_name = models.CharField(max_length=30)
11    last_name = models.CharField(max_length=30)
12
13    def _get_full_name(self):
14        return "%s %s" % (self.first_name, self.last_name)
15
16    def _set_full_name(self, combined_name):
17        self.first_name, self.last_name = combined_name.split(' ', 1)
18
19    full_name = property(_get_full_name)
20
21    full_name_2 = property(_get_full_name, _set_full_name)