mirror of
https://github.com/django/django.git
synced 2025-08-04 02:48:35 +00:00
Merged regressiontests and modeltests into the test root.
This commit is contained in:
parent
b3d2ccb5bf
commit
89f40e3624
1050 changed files with 0 additions and 0 deletions
22
tests/properties/models.py
Normal file
22
tests/properties/models.py
Normal file
|
@ -0,0 +1,22 @@
|
|||
"""
|
||||
22. Using properties on models
|
||||
|
||||
Use properties on models just like on any other Python object.
|
||||
"""
|
||||
|
||||
from django.db import models
|
||||
|
||||
|
||||
class Person(models.Model):
|
||||
first_name = models.CharField(max_length=30)
|
||||
last_name = models.CharField(max_length=30)
|
||||
|
||||
def _get_full_name(self):
|
||||
return "%s %s" % (self.first_name, self.last_name)
|
||||
|
||||
def _set_full_name(self, combined_name):
|
||||
self.first_name, self.last_name = combined_name.split(' ', 1)
|
||||
|
||||
full_name = property(_get_full_name)
|
||||
|
||||
full_name_2 = property(_get_full_name, _set_full_name)
|
Loading…
Add table
Add a link
Reference in a new issue