Login

Snippets by JoeLinux

Snippet List

Gravatar support in model save override

Overridden save() method that adds Gravatar support for a user with a profile photo field (and presumably an email field). Checks to see if user has provided a photo. If not, then query Gravatar for a possible photo. Finally, if Gravatar does not have an appropriate photo for this user, then use whatever default photo is available (in this case, 'users/photos/default_profile_photo.png'... change as necessary).

  • model
  • save
  • override
Read More

Retrieve human-readable value from choices tuple or value from dict

Will help you retrieve the value from a dictionary with a supplied key, or the human-readable value from a choices tuple. Works as follows: To retrieve the value of a dict: `{{ crime_rates_dict|getval:"Chicago" }}` <-- will return value of `crime_rates_dict["Chicago"]` To retrieve the human-readable value from a choices tuple: `{{ country.COUNTRIES|getval:"US" }}` <-- will return "United States" in `COUNTRIES = (("US", "United States"),)`

  • template
  • templatetag
  • choices
  • dict
  • tuple
Read More

JoeLinux has posted 3 snippets.