Undocumented Django: Overriding _get_FIELD_url and friends
Monday, April 21st, 2008Recently I found the need to override the _get_FIELD_url() for a particular set of models in my Django app. The _get_FIELD_*() methods provide your FileField and ImageField with “magic” convenience methods. For example:
from django.db import models
class MyModel(models.Model):
file = models.FileField(upload_to='some/path')
If you want to to retrieve the URL for the file you would use:
m = MyModel().objects.get(id=1)
m.get_file_url()
Notice that your class automagically gets a method called “get_file_url()”. This is the “magic” part and all of this is done behind the scenes for you. While this is really convenient for getting things done most of the time, there are some times where you need to have more control over what’s returned by these magic methods.


