blob: c900091b6410530d733a279bdcd3f5d5c877f513 (
plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
|
"""
17. Custom column names
If your database column name is different than your model attribute, use the
``db_column`` parameter. Note that you'll use the field's name, not its column
name, in API usage.
"""
from django.core import meta
class Person(meta.Model):
first_name = meta.CharField(maxlength=30, db_column='firstname')
last_name = meta.CharField(maxlength=30, db_column='last')
def __repr__(self):
return '%s %s' % (self.first_name, self.last_name)
API_TESTS = """
# Create a Person.
>>> p = persons.Person(first_name='John', last_name='Smith')
>>> p.save()
>>> p.id
1
>>> persons.get_list()
[John Smith]
>>> persons.get_list(first_name__exact='John')
[John Smith]
>>> persons.get_object(first_name__exact='John')
John Smith
>>> persons.get_list(firstname__exact='John')
Traceback (most recent call last):
...
TypeError: got unexpected keyword argument 'firstname__exact'
>>> p = persons.get_object(last_name__exact='Smith')
>>> p.first_name
'John'
>>> p.last_name
'Smith'
>>> p.firstname
Traceback (most recent call last):
...
AttributeError: 'Person' object has no attribute 'firstname'
>>> p.last
Traceback (most recent call last):
...
AttributeError: 'Person' object has no attribute 'last'
"""
|