Ticket #6574: db_type_none.diff

File db_type_none.diff, 1.6 KB (added by oyvind, 17 years ago)

Added patch with tests for queryset-refactor

  • django/db/models/sql/query.py

    diff --git a/django/db/models/sql/query.py b/django/db/models/sql/query.py
    index 7d95e1d..18a8248 100644
    a b class Query(object):  
    390390        elif self.default_cols:
    391391            table_alias = self.tables[0]
    392392            result = ['%s.%s' % (qn(table_alias), qn(f.column))
    393                     for f in self.model._meta.fields]
     393                    for f in self.model._meta.fields if f.db_type()]
    394394            aliases = result[:]
    395395
    396396        result.extend(['(%s) AS %s' % (col, alias)
  • new file tests/modeltests/db_type/models.py

    diff --git a/tests/modeltests/db_type/__init__.py b/tests/modeltests/db_type/__init__.py
    new file mode 100644
    index 0000000..e69de29
    diff --git a/tests/modeltests/db_type/__init__.pyc b/tests/modeltests/db_type/__init__.pyc
    new file mode 100644
    index 0000000..d0cb950
    Binary files /dev/null and b/tests/modeltests/db_type/__init__.pyc differ
    diff --git a/tests/modeltests/db_type/models.py b/tests/modeltests/db_type/models.py
    new file mode 100644
    index 0000000..52d8bcb
    - +  
     1"""
     2This is a test for db_type None
     3"""
     4
     5from django.db import models
     6
     7class NoneCharField(models.CharField):
     8
     9    def db_type(self):
     10        return None
     11
     12class NoneTypeModel(models.Model):
     13   
     14    real_field = models.CharField(max_length=20)
     15    fake_field = NoneCharField(max_length=20)
     16
     17    def __unicode__(self):
     18        return self.real_field
     19
     20__test__ = {'API_TESTS': """
     21# test
     22>>> qs = NoneTypeModel.objects.all()
     23>>> str(qs.query.as_sql()).find('fake_field')==-1
     24True
     25"""}
Back to Top