How to Properly Hide and Show Elements Using Javascript

What is the first solution comes to your mind, when someone asks you

How can I dynamically hide any element using Javascript ?

The obvious solutions to this is to set “display” style to “none”. Something like this:

document.getElementById('element').style.display = 'none';

This will surely work, but is it the correct way to do so? May be not, as you would face problems in showing that element again. The problem in showing that element is that you don’t know the original display property of that element.

Read More …

Django Example: FileField and ImageField

The syntax to add it in Model is:

class MyModel(models.Model):
	video = FileField(upload_to=None[, max_length=100, **options])

Here upload_to is local filesystem path that will be appended to your MEDIA_ROOT setting to determine the value of the url(mymodel.video.url) attribute.

Setting MEDIA_ROOT and upload_to

If,
MEDIA_ROOT = ‘/home/myname/files/
upload_to=’videos’
file: abc.flv
results in: /home/myname/files/videos/abc.flv

where as if,
MEDIA_ROOT = ‘/home/myname/files/’
upload_to=’/videos
and file : abc.flv
result will be saved in : ‘/videos/abc.flv’ (i.e., root directory of filesystem)

You can also set upload_to=’videos/%Y/%m/%d’.

Read More …