Exemple #1
0
    def default(self, o):
        
        if isinstance(o, Promise):
            return force_unicode(o)
        elif isinstance(o, ValuesQuerySet):
            return list(o)
        
        elif isinstance(o, QuerySet):
            return map(self.default, o)
        
        elif isinstance(o, datetime.date):
            return o.strftime(self.date_fromat)
        elif isinstance(o, models.Model):
            field_names = map(lambda f: f.name, o._meta.fields)
            # Búsqueda de campos extra
            extra_json_fields = getattr(o, 'extra_json_fields', None)
            if extra_json_fields:
                field_names.extend(extra_json_fields)
            
            data = dict(map(lambda name: (name, getattr(o, name)), field_names))
            data['__unicode__'] = unicode(o)
            
            return data
        elif isinstance(o, decimal.Decimal):
            return str(o)
#        elif isinstance(o, datetime.datetime):
#            d = datetime_safe.new_datetime(o)
#            return d.strftime("%s %s" % (self.DATE_FORMAT, self.TIME_FORMAT))
        return DateTimeAwareJSONEncoder.default(self, o)
Exemple #2
0
    def default(self, o):
        if isinstance(o, Promise):
            return force_unicode(o)
#        elif isinstance(o, datetime.datetime):
#            d = datetime_safe.new_datetime(o)
#            return d.strftime("%s %s" % (self.DATE_FORMAT, self.TIME_FORMAT))
        return DateTimeAwareJSONEncoder.default(self, o)