Ticket #14003: 14003-testcase.patch
File 14003-testcase.patch, 1.8 KB (added by , 13 years ago) |
---|
-
tests/modeltests/custom_pk/tests.py
4 4 from django.db import transaction, IntegrityError 5 5 from django.test import TestCase, skipIfDBFeature 6 6 7 from .models import Employee, Business, Bar, Foo 7 from .models import Employee, Business, Bar, Foo, Author, Book 8 8 9 9 10 10 class CustomPKTests(TestCase): … … 179 179 Employee.objects.create, first_name="Tom", last_name="Smith" 180 180 ) 181 181 transaction.savepoint_rollback(sid) 182 183 def test_filter_on_reverse_relation(self): 184 author = Author.objects.create(name='Me') 185 book = Book.objects.create(name='My book', author=author) 186 self.assertQuerysetEqual( 187 Author.objects.filter(book=book), 188 ["Me"], 189 lambda a: a.name) -
tests/modeltests/custom_pk/models.py
14 14 15 15 16 16 class Employee(models.Model): 17 employee_code = models.IntegerField(primary_key=True, db_column ='code')17 employee_code = models.IntegerField(primary_key=True, db_column='code') 18 18 first_name = models.CharField(max_length=20) 19 19 last_name = models.CharField(max_length=20) 20 20 class Meta: … … 38 38 def __unicode__(self): 39 39 return repr(self.pk) 40 40 41 42 41 class Foo(models.Model): 43 42 bar = models.ForeignKey(Bar) 44 43 44 class Author(models.Model): 45 name = models.CharField(max_length=255) 46 47 class Book(models.Model): 48 name = models.CharField(max_length=50, primary_key=True) 49 author = models.ForeignKey(Author)