Ticket #16978: 16978.patch

File 16978.patch, 2.4 KB (added by Jonas Obrist, 13 years ago)

tests & fix

  • django/db/models/fields/related.py

    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):  
    4949    if relation == RECURSIVE_RELATIONSHIP_CONSTANT:
    5050        app_label = cls._meta.app_label
    5151        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
    5355    else:
    5456        # Look for an "app.Model" relation
    5557        try:
  • new file tests/modeltests/foreign_key/models.py

    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 -*-
     2from django.db import models
     3
     4class RelatedModel(models.Model):
     5    def split(self):
     6        pass
     7 No newline at end of file
  • new file tests/modeltests/foreign_key/tests.py

    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 -*-
     2from django.db import models
     3from django.test.testcases import TestCase
     4
     5
     6class 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
Back to Top