From 51c3ba1996869e5229033127444c4eaeed299b15 Mon Sep 17 00:00:00 2001
From: Jonas Obrist <ojiidotch@gmail.com>
Date: Sun, 25 Dec 2011 17:53:32 +0100
Subject: [PATCH] wrote a test for #16978 wrote a fix for #16978
---
django/db/models/fields/related.py | 4 +++-
tests/modeltests/foreign_key/models.py | 6 ++++++
tests/modeltests/foreign_key/tests.py | 17 +++++++++++++++++
3 files changed, 26 insertions(+), 1 deletions(-)
create mode 100644 tests/modeltests/foreign_key/__init__.py
create mode 100644 tests/modeltests/foreign_key/models.py
create mode 100644 tests/modeltests/foreign_key/tests.py
diff --git a/django/db/models/fields/related.py b/django/db/models/fields/related.py
index 848fd6e..a276e5d 100644
a
|
b
|
class MyModel(Model):
|
49 | 49 | if relation == RECURSIVE_RELATIONSHIP_CONSTANT: |
50 | 50 | app_label = cls._meta.app_label |
51 | 51 | model_name = cls.__name__ |
52 | | |
| 52 | elif not isinstance(relation, basestring): |
| 53 | app_label = relation._meta.app_label |
| 54 | model_name = relation._meta.object_name |
53 | 55 | else: |
54 | 56 | # Look for an "app.Model" relation |
55 | 57 | try: |
diff --git a/tests/modeltests/foreign_key/__init__.py b/tests/modeltests/foreign_key/__init__.py
new file mode 100644
index 0000000..e69de29
diff --git a/tests/modeltests/foreign_key/models.py b/tests/modeltests/foreign_key/models.py
new file mode 100644
index 0000000..6e2e4de
-
|
+
|
|
| 1 | # -*- coding: utf-8 -*- |
| 2 | from django.db import models |
| 3 | |
| 4 | class RelatedModel(models.Model): |
| 5 | def split(self): |
| 6 | pass |
| 7 | No newline at end of file |
diff --git a/tests/modeltests/foreign_key/tests.py b/tests/modeltests/foreign_key/tests.py
new file mode 100644
index 0000000..01acdc5
-
|
+
|
|
| 1 | # -*- coding: utf-8 -*- |
| 2 | from django.db import models |
| 3 | from django.test.testcases import TestCase |
| 4 | |
| 5 | |
| 6 | class AddLazyRelationsTests(TestCase): |
| 7 | def test_model_with_split_method(self): |
| 8 | class Meta: |
| 9 | order_with_respect_to = 'related' |
| 10 | |
| 11 | attrs = { |
| 12 | 'related': models.ForeignKey('foreign_key.RelatedModel'), |
| 13 | '__module__': self.__module__, |
| 14 | 'Meta': Meta, |
| 15 | } |
| 16 | MainModel = type('MainModel', (models.Model, ), attrs) |
| 17 | |