~ubuntu-branches/ubuntu/jaunty/python-django/jaunty-backports

« back to all changes in this revision

Viewing changes to tests/regressiontests/string_lookup/models.py

  • Committer: Bazaar Package Importer
  • Author(s): Scott James Remnant
  • Date: 2008-11-15 19:15:33 UTC
  • mfrom: (1.1.6 upstream)
  • Revision ID: james.westby@ubuntu.com-20081115191533-xbt1ut2xf4fvwtvc
Tags: 1.0.1-0ubuntu1
* New upstream release:
  - Bug fixes.

* The tests/ sub-directory appaers to have been dropped upstream, so pull
  our patch to workaround the tests and modify the rules.

Show diffs side-by-side

added added

removed removed

Lines of Context:
1
 
# -*- coding: utf-8 -*-
2
 
from django.db import models
3
 
 
4
 
class Foo(models.Model):
5
 
    name = models.CharField(max_length=50)
6
 
    friend = models.CharField(max_length=50, blank=True)
7
 
 
8
 
    def __unicode__(self):
9
 
        return "Foo %s" % self.name
10
 
 
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")
16
 
 
17
 
    def __unicode__(self):
18
 
        return "Bar %s" % self.place.name
19
 
 
20
 
class Whiz(models.Model):
21
 
    name = models.CharField(max_length=50)
22
 
 
23
 
    def __unicode__(self):
24
 
        return "Whiz %s" % self.name
25
 
 
26
 
class Child(models.Model):
27
 
    parent = models.OneToOneField('Base')
28
 
    name = models.CharField(max_length=50)
29
 
 
30
 
    def __unicode__(self):
31
 
        return "Child %s" % self.name
32
 
 
33
 
class Base(models.Model):
34
 
    name = models.CharField(max_length=50)
35
 
 
36
 
    def __unicode__(self):
37
 
        return "Base %s" % self.name
38
 
 
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)
43
 
 
44
 
    def __str__(self):
45
 
        return "Article %s" % self.name
46
 
 
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.
50
 
 
51
 
>>> f1 = Foo(name="Foo1")
52
 
>>> f1.save()
53
 
>>> f2 = Foo(name="Foo2")
54
 
>>> f2.save()
55
 
 
56
 
>>> w1 = Whiz(name="Whiz1")
57
 
>>> w1.save()
58
 
 
59
 
>>> b1 = Bar(name="Bar1", normal=f1, fwd=w1, back=f2)
60
 
>>> b1.save()
61
 
 
62
 
>>> b1.normal
63
 
<Foo: Foo Foo1>
64
 
 
65
 
>>> b1.fwd
66
 
<Whiz: Whiz Whiz1>
67
 
 
68
 
>>> b1.back
69
 
<Foo: Foo Foo2>
70
 
 
71
 
>>> base1 = Base(name="Base1")
72
 
>>> base1.save()
73
 
 
74
 
>>> child1 = Child(name="Child1", parent=base1)
75
 
>>> child1.save()
76
 
 
77
 
>>> child1.parent
78
 
<Base: Base Base1>
79
 
 
80
 
# Regression tests for #3937: make sure we can use unicode characters in
81
 
# queries.
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.
84
 
 
85
 
>>> fx = Foo(name='Bjorn', friend=u'François')
86
 
>>> fx.save()
87
 
>>> Foo.objects.get(friend__contains=u'\xe7')
88
 
<Foo: Foo Bjorn>
89
 
 
90
 
# We can also do the above query using UTF-8 strings.
91
 
>>> Foo.objects.get(friend__contains='\xc3\xa7')
92
 
<Foo: Foo Bjorn>
93
 
 
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.')
96
 
>>> a.save()
97
 
>>> Article.objects.get(text__exact='The quick brown fox jumps over the lazy dog.')
98
 
<Article: Article Test>
99
 
 
100
 
>>> Article.objects.get(text__contains='quick brown fox')
101
 
<Article: Article Test>
102
 
 
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>]
108
 
 
109
 
"""}