Django

Code

Changeset 4105

Show
Ignore:
Timestamp:
11/25/06 20:38:04 (2 years ago)
Author:
russellm
Message:

Fixes #2993, Refs #2918 -- Reverted [3960]; [3960] fixed a potential data validation problem for SQLite, but broke usage of LazyDate?. The proper fix is to complete the model validators to catch _all_ invalid inputs.

Files:

Legend:

Unmodified
Added
Removed
Modified
Copied
Moved
  • django/trunk/django/db/models/fields/__init__.py

    r4036 r4105  
    458458    def get_db_prep_save(self, value): 
    459459        # Casts dates into string format for entry into database. 
    460         if isinstance(value, datetime.datetime): 
    461             value = value.date().strftime('%Y-%m-%d') 
    462         elif isinstance(value, datetime.date): 
     460        if value is not None: 
    463461            value = value.strftime('%Y-%m-%d') 
    464462        return Field.get_db_prep_save(self, value) 
     
    490488    def get_db_prep_save(self, value): 
    491489        # Casts dates into string format for entry into database. 
    492         if isinstance(value, datetime.datetime)
     490        if value is not None
    493491            # MySQL will throw a warning if microseconds are given, because it 
    494492            # doesn't support microseconds. 
     
    496494                value = value.replace(microsecond=0) 
    497495            value = str(value) 
    498         elif isinstance(value, datetime.date): 
    499             # MySQL will throw a warning if microseconds are given, because it 
    500             # doesn't support microseconds. 
    501             if settings.DATABASE_ENGINE == 'mysql' and hasattr(value, 'microsecond'): 
    502                 value = datetime.datetime(value.year, value.month, value.day, microsecond=0) 
    503             value = str(value) 
    504              
    505496        return Field.get_db_prep_save(self, value) 
    506497