[Answered ]-Construct attribute value of django form

2👍

class ImageUploadFileForm(forms.ModelForm):
    class Meta:
        model = Photo
        fields = [ 'image' ]

    def __init__(self, *args, **kwargs):
        self.something = kwargs.pop('something')
        super(ImageUploadFileForm, self).__init__(*args, **kwargs)
        self.fields['image'] = cloudinary.forms.CloudinaryJsFileField({ 'public_id': self.something })

Then

uploadform = ImageUploadFileForm(instance=whatever, something='BLAHBLAHBLAH')

Pretty standard way of passing arguments to form constructor.

Leave a comment