1
# -*- coding: utf-8 -*-
2
from django.db import models
4
class Foo(models.Model):
5
name = models.CharField(max_length=50)
6
friend = models.CharField(max_length=50, blank=True)
9
return "Foo %s" % self.name
11
class Bar(models.Model):
12
name = models.CharField(max_length=50)
13
normal = models.ForeignKey(Foo, related_name='normal_foo')
14
fwd = models.ForeignKey("Whiz")
15
back = models.ForeignKey("Foo")
17
def __unicode__(self):
18
return "Bar %s" % self.place.name
20
class Whiz(models.Model):
21
name = models.CharField(max_length=50)
23
def __unicode__(self):
24
return "Whiz %s" % self.name
26
class Child(models.Model):
27
parent = models.OneToOneField('Base')
28
name = models.CharField(max_length=50)
30
def __unicode__(self):
31
return "Child %s" % self.name
33
class Base(models.Model):
34
name = models.CharField(max_length=50)
36
def __unicode__(self):
37
return "Base %s" % self.name
39
class Article(models.Model):
40
name = models.CharField(max_length=50)
41
text = models.TextField()
42
submitted_from = models.IPAddressField(blank=True, null=True)
45
return "Article %s" % self.name
47
__test__ = {'API_TESTS': ur"""
48
# Regression test for #1661 and #1662: Check that string form referencing of
49
# models works, both as pre and post reference, on all RelatedField types.
51
>>> f1 = Foo(name="Foo1")
53
>>> f2 = Foo(name="Foo2")
56
>>> w1 = Whiz(name="Whiz1")
59
>>> b1 = Bar(name="Bar1", normal=f1, fwd=w1, back=f2)
71
>>> base1 = Base(name="Base1")
74
>>> child1 = Child(name="Child1", parent=base1)
80
# Regression tests for #3937: make sure we can use unicode characters in
82
# BUG: These tests fail on MySQL, but it's a problem with the test setup. A
83
# properly configured UTF-8 database can handle this.
85
>>> fx = Foo(name='Bjorn', friend=u'François')
87
>>> Foo.objects.get(friend__contains=u'\xe7')
90
# We can also do the above query using UTF-8 strings.
91
>>> Foo.objects.get(friend__contains='\xc3\xa7')
94
# Regression tests for #5087: make sure we can perform queries on TextFields.
95
>>> a = Article(name='Test', text='The quick brown fox jumps over the lazy dog.')
97
>>> Article.objects.get(text__exact='The quick brown fox jumps over the lazy dog.')
98
<Article: Article Test>
100
>>> Article.objects.get(text__contains='quick brown fox')
101
<Article: Article Test>
103
# Regression test for #708: "like" queries on IP address fields require casting
104
# to text (on PostgreSQL).
105
>>> Article(name='IP test', text='The body', submitted_from='192.0.2.100').save()
106
>>> Article.objects.filter(submitted_from__contains='192.0.2')
107
[<Article: Article IP test>]