mirror of
https://github.com/django/django.git
synced 2025-07-18 18:55:18 +00:00
Ported over Field.deconstruct() from my schema alteration branch.
This is to help other ongoing branches which would benefit from this functionality.
This commit is contained in:
parent
8809da67a2
commit
48dd1e63bb
6 changed files with 501 additions and 1 deletions
|
@ -227,6 +227,17 @@ class FileField(Field):
|
|||
kwargs['max_length'] = kwargs.get('max_length', 100)
|
||||
super(FileField, self).__init__(verbose_name, name, **kwargs)
|
||||
|
||||
def deconstruct(self):
|
||||
name, path, args, kwargs = super(FileField, self).deconstruct()
|
||||
if kwargs.get("max_length", None) != 100:
|
||||
kwargs["max_length"] = 100
|
||||
else:
|
||||
del kwargs["max_length"]
|
||||
kwargs['upload_to'] = self.upload_to
|
||||
if self.storage is not default_storage:
|
||||
kwargs['storage'] = self.storage
|
||||
return name, path, args, kwargs
|
||||
|
||||
def get_internal_type(self):
|
||||
return "FileField"
|
||||
|
||||
|
@ -326,6 +337,14 @@ class ImageField(FileField):
|
|||
self.width_field, self.height_field = width_field, height_field
|
||||
super(ImageField, self).__init__(verbose_name, name, **kwargs)
|
||||
|
||||
def deconstruct(self):
|
||||
name, path, args, kwargs = super(ImageField, self).deconstruct()
|
||||
if self.width_field:
|
||||
kwargs['width_field'] = self.width_field
|
||||
if self.height_field:
|
||||
kwargs['height_field'] = self.height_field
|
||||
return name, path, args, kwargs
|
||||
|
||||
def contribute_to_class(self, cls, name):
|
||||
super(ImageField, self).contribute_to_class(cls, name)
|
||||
# Attach update_dimension_fields so that dimension fields declared
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue