The Starfish story

No matter how big or small our actions are, they will always make a difference for someone and add to the global efforts to solve the world’s challenges.

There was once a man who used to go to the ocean to get inspiration.

One day as he walked along the shore, he looked down the beach and saw a person throwing something into the ocean.
As he got closer, he saw that it was a young man, and the young man was reaching down to the shore, picking up starfish, and very gently throwing them into the ocean.

– “Good morning young man! What are you doing?”, Asked the wise man.

The young man paused, looked up, and replied:
– “Don’t you see? I am throwing starfish into the ocean. The sun is rising, and the tide is out. And if I don’t throw them back into the ocean, they’ll die out here.”
– “But, young man, don’t you realize that there are miles of beach and thousands of starfish all along it? You can’t possibly make a difference or save them all!”
The man told the young boy.

The young man, listening politely, bent down and picked up another starfish, throwing it into the sea past the breaking waves.
Turning to the old man, he modestly replied,

“It made a difference for that one.”

The writer silently walked to a nearby starfish and threw it in the ocean… and another… and more people passing by joined. Before dusk, the beach was bare.

No matter how big or small our actions are, they will always make a difference for someone and add to the global efforts to solve the world’s challenges.

 

Need to use an ImageField in Django with a limit on filesize while still allowing empty entries?

Here’s a class that subclasses the ImageField and allows you to set a limit on filesize while still allowing empty entries.


class ImageField50KB(forms.ImageField):
    def __init__(self, *args, **kwargs):
        super(ImageField50KB, self).__init__(*args, **kwargs)

        self.label = (u'Passport (Max 50kB)')

        self.helptext = (u'Attach a current passport photograph')

    def clean(self, data, initial):
        if not data and initial:
            return initial
        f = super(ImageField50KB, self).clean(data)

        if not (f.size <= 50000):
             raise forms.ValidationError((u'Image is too large, Maximum filesize allowed is 50kB' ))
        return f

To use this in your form, copy the code into forms.py and add the following to the form definition:


	image= ImageField50KB(
		widget=forms.FileInput,
		initial=BLANK_IMAGE,
	 )

where BLANK_IMAGE has been declared already to point to a file that will be used as default image in case the field is empty.