Fixed #5574 -- Serialize a FileField using its filename from the database, not
external URL. The problem showed up when reloading the data. Patch from Chris Henderson. git-svn-id: http://code.djangoproject.com/svn/django/trunk@7293 bcc190cf-cafb-0310-a4f2-bffc1f526a37
This commit is contained in:
parent
73328bf8ec
commit
5b8974c7b3
|
@ -22,10 +22,10 @@ class Serializer(object):
|
|||
Abstract serializer base class.
|
||||
"""
|
||||
|
||||
# Indicates if the implemented serializer is only available for
|
||||
# Indicates if the implemented serializer is only available for
|
||||
# internal Django use.
|
||||
internal_use_only = False
|
||||
|
||||
|
||||
def serialize(self, queryset, **options):
|
||||
"""
|
||||
Serialize a queryset.
|
||||
|
@ -60,8 +60,6 @@ class Serializer(object):
|
|||
"""
|
||||
if isinstance(field, models.DateTimeField):
|
||||
value = getattr(obj, field.name).strftime("%Y-%m-%d %H:%M:%S")
|
||||
elif isinstance(field, models.FileField):
|
||||
value = getattr(obj, "get_%s_url" % field.name, lambda: None)()
|
||||
else:
|
||||
value = field.flatten_data(follow=None, obj=obj).get(field.name, "")
|
||||
return smart_unicode(value)
|
||||
|
@ -162,9 +160,9 @@ class DeserializedObject(object):
|
|||
return "<DeserializedObject: %s>" % smart_str(self.object)
|
||||
|
||||
def save(self, save_m2m=True):
|
||||
# Call save on the Model baseclass directly. This bypasses any
|
||||
# Call save on the Model baseclass directly. This bypasses any
|
||||
# model-defined save. The save is also forced to be raw.
|
||||
# This ensures that the data that is deserialized is literally
|
||||
# This ensures that the data that is deserialized is literally
|
||||
# what came from the file, not post-processed by pre_save/save
|
||||
# methods.
|
||||
models.Model.save(self.object, raw=True)
|
||||
|
|
Loading…
Reference in New Issue