~ubuntu-branches/debian/sid/python-django/sid

« back to all changes in this revision

Viewing changes to tests/modeltests/properties/models.py

  • Committer: Package Import Robot
  • Author(s): Luke Faraone
  • Date: 2013-11-07 15:33:49 UTC
  • mfrom: (1.3.12)
  • Revision ID: package-import@ubuntu.com-20131107153349-e31sc149l2szs3jb
Tags: 1.6-1
* New upstream version. Closes: #557474, #724637.
* python-django now also suggests the installation of ipython,
  bpython, python-django-doc, and libgdal1.
  Closes: #636511, #686333, #704203
* Set package maintainer to Debian Python Modules Team.
* Bump standards version to 3.9.5, no changes needed.

Show diffs side-by-side

added added

removed removed

Lines of Context:
1
 
"""
2
 
22. Using properties on models
3
 
 
4
 
Use properties on models just like on any other Python object.
5
 
"""
6
 
 
7
 
from django.db import models
8
 
 
9
 
 
10
 
class Person(models.Model):
11
 
    first_name = models.CharField(max_length=30)
12
 
    last_name = models.CharField(max_length=30)
13
 
 
14
 
    def _get_full_name(self):
15
 
        return "%s %s" % (self.first_name, self.last_name)
16
 
 
17
 
    def _set_full_name(self, combined_name):
18
 
        self.first_name, self.last_name = combined_name.split(' ', 1)
19
 
 
20
 
    full_name = property(_get_full_name)
21
 
 
22
 
    full_name_2 = property(_get_full_name, _set_full_name)