Code

Ticket #5223: sqlite_year_lookup_fix.diff

File sqlite_year_lookup_fix.diff, 752 bytes (added by Manuel Saelices <msaelices@…>, 7 years ago)

A patch that fixes sqlite year lookup

Line 
1Index: models/fields/__init__.py
2===================================================================
3--- models/fields/__init__.py   (revisión: 5991)
4+++ models/fields/__init__.py   (copia de trabajo)
5@@ -507,6 +507,12 @@
6             value = value.strftime('%Y-%m-%d')
7         else:
8             value = smart_unicode(value)
9+        if lookup_type == 'year' and settings.DATABASE_ENGINE == 'sqlite3':
10+            try:
11+                value = int(value)
12+            except ValueError:
13+                raise ValueError("The __year lookup type requires an integer argument")
14+            return ['%s-01-01' % value, '%s-12-31' % value]
15         return Field.get_db_prep_lookup(self, lookup_type, value)
16 
17     def pre_save(self, model_instance, add):