Ticket #13941: 13941.patch

File 13941.patch, 3.5 KB (added by Ales Zoulek, 14 years ago)

patch and tests

  • django/db/backends/postgresql/operations.py

    diff --git a/django/db/backends/postgresql/operations.py b/django/db/backends/postgresql/operations.py
    index 76f2541..785d301 100644
    a b class DatabaseOperations(BaseDatabaseOperations):  
    132132                if not f.rel.through:
    133133                    output.append("%s setval(pg_get_serial_sequence('%s','%s'), coalesce(max(%s), 1), max(%s) %s null) %s %s;" % \
    134134                        (style.SQL_KEYWORD('SELECT'),
    135                         style.SQL_TABLE(model._meta.db_table),
     135                        style.SQL_TABLE(qn(f.m2m_db_table())),
    136136                        style.SQL_FIELD('id'),
    137137                        style.SQL_FIELD(qn('id')),
    138138                        style.SQL_FIELD(qn('id')),
  • tests/regressiontests/backends/models.py

    diff --git a/tests/regressiontests/backends/models.py b/tests/regressiontests/backends/models.py
    index e3137f2..c985573 100644
    a b from django.conf import settings  
    22from django.db import models
    33from django.db import connection, DEFAULT_DB_ALIAS
    44
     5from django.contrib.contenttypes import generic
     6from django.contrib.contenttypes.models import ContentType
     7
     8
    59
    610class Square(models.Model):
    711    root = models.IntegerField()
    if settings.DATABASES[DEFAULT_DB_ALIAS]['ENGINE'] != 'django.db.backends.mysql':  
    3741        m2m_also_quite_long_zzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzz = models.ManyToManyField(Person,blank=True)
    3842
    3943
     44class Tag(models.Model):
     45    name = models.CharField(max_length=30)
     46    content_type = models.ForeignKey(ContentType)
     47    object_id = models.PositiveIntegerField()
     48    content_object = generic.GenericForeignKey('content_type', 'object_id')
     49
     50
     51class Post(models.Model):
     52    name = models.CharField(max_length=30)
     53    text = models.TextField()
     54    tags = generic.GenericRelation('Tag')
     55
     56
    4057qn = connection.ops.quote_name
    4158
    4259__test__ = {'API_TESTS': """
  • tests/regressiontests/backends/tests.py

    diff --git a/tests/regressiontests/backends/tests.py b/tests/regressiontests/backends/tests.py
    index ee3ccdc..146ff27 100644
    a b import unittest  
    66from django.conf import settings
    77from django.core import management
    88from django.core.management.color import no_style
    9 from django.db import backend, connection, DEFAULT_DB_ALIAS
     9from django.db import backend, connection, connections, DEFAULT_DB_ALIAS
    1010from django.db.backends.signals import connection_created
    1111from django.test import TestCase
    1212
    if settings.DATABASES[DEFAULT_DB_ALIAS]['ENGINE'] != 'django.db.backends.mysql':  
    137137            for statement in connection.ops.sql_flush(no_style(), tables, sequences):
    138138                cursor.execute(statement)
    139139
     140if settings.DATABASES[DEFAULT_DB_ALIAS]['ENGINE'] == 'django.db.backends.postgresql_psycopg2':
     141    class PostgresResetSequenceTest(TestCase):
     142
     143        def test_generic_relation(self):
     144            cursor = connection.cursor()
     145            models.Post.objects.create(id=10, name='1st post', text='hello world')
     146            commands = connections[DEFAULT_DB_ALIAS].ops.sequence_reset_sql(no_style(), [models.Post])
     147            for sql in commands:
     148                cursor.execute(sql)
     149            cursor.execute("SELECT nextval(pg_get_serial_sequence('backends_post','id'))")
     150            self.assertEqual(cursor.fetchone()[0], 11)
     151
     152
     153
    140154
    141155def connection_created_test(sender, **kwargs):
    142156    print 'connection_created signal'
Back to Top