Ticket #14003: 14003-testcase.patch

File 14003-testcase.patch, 1.8 KB (added by Aymeric Augustin, 13 years ago)
  • tests/modeltests/custom_pk/tests.py

     
    44from django.db import transaction, IntegrityError
    55from django.test import TestCase, skipIfDBFeature
    66
    7 from .models import Employee, Business, Bar, Foo
     7from .models import Employee, Business, Bar, Foo, Author, Book
    88
    99
    1010class CustomPKTests(TestCase):
     
    179179            Employee.objects.create, first_name="Tom", last_name="Smith"
    180180        )
    181181        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

     
    1414
    1515
    1616class 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')
    1818    first_name = models.CharField(max_length=20)
    1919    last_name = models.CharField(max_length=20)
    2020    class Meta:
     
    3838    def __unicode__(self):
    3939        return repr(self.pk)
    4040
    41 
    4241class Foo(models.Model):
    4342    bar = models.ForeignKey(Bar)
    4443
     44class Author(models.Model):
     45    name = models.CharField(max_length=255)
     46
     47class Book(models.Model):
     48    name = models.CharField(max_length=50, primary_key=True)
     49    author = models.ForeignKey(Author)
Back to Top