Opened 10 years ago

Closed 9 years ago

#560 closed defect (wontfix)

Fields which have several formfields are non-trivial to use in forms.

Reported by: wojtek3@… Owned by: adrian
Component: Core (Other) Version:
Severity: normal Keywords:
Cc: wojtek3@… Triage Stage: Unreviewed
Has patch: no Needs documentation: no
Needs tests: no Patch needs improvement: no
Easy pickings: UI/UX:


Fields like the FileField which have multiple form fields need the programmer to reference them twice in a form, which isn't good practice. Instead of doing {{ field }} the programmer has to do {{ field }} and {{ field_file }} (for a file field). I believe that doing {{ field }} should output the whole HTML for taht given model field and not make the programmer think about how many formfields are actually needed for that field.

Fixing this would simply require changes to FormWrapper and FormFieldWrapper.

Another issue I have encountered is how FileField/ImageField are limited. I wanted to store my files in MogileFS instead of the filesystem and had to write my own field for that. It would be nice if FileField could take a parameter being a function that will be called on the newly uploaded file name/data/DB object and would take care of placing it in whatever storage is needed, scaling it to various dimensions, and so on.

Here is a suggested implementation (I use 'foo' for 'upload_to' parameter since it's required and never used):

class GenericImageField (fields.ImageField):
    def __init__(self, name, process, **kwargs):
        fields.ImageField.__init__(self, name, **dict(kwargs, upload_to = 'foo'))
        self.process = process
    def save_file(self, new_data, new_object, original_object, change, rel):
        upload_field_name = self.get_manipulator_field_names('')[0]
        if new_data.get(upload_field_name, False):
            for f in self.process:
                if rel:
                    f(self, new_object, new_data[upload_field_name][0]["filename"], new_data[upload_field_name][0]["content"])
                    f(self, new_object, new_data[upload_field_name]["filename"], new_data[upload_field_name]["content"])                    

Change History (1)

comment:1 Changed 9 years ago by SmileyChris

  • Resolution set to wontfix
  • Status changed from new to closed

Made obsolete by upcoming newforms

Note: See TracTickets for help on using tickets.
Back to Top