- Author:
- macat
- Posted:
- November 18, 2010
- Language:
- Python
- Version:
- Not specified
- Score:
- 0 (after 0 ratings)
I returns the astrological sign.
http://en.wikipedia.org/wiki/Zodiac
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 | @register.filter
def astrological_sign(bday):
if bday.month == 1 and bday.day >= 20 or bday.month == 2 and bday.day < 18:
return 'aquarius'
if bday.month == 2 and bday.day >= 18 or bday.month == 3 and bday.day < 20:
return 'pisces'
if bday.month == 3 and bday.day >= 20 or bday.month == 4 and bday.day < 20:
return 'aries'
if bday.month == 4 and bday.day >= 20 or bday.month == 5 and bday.day < 21:
return 'taurus'
if bday.month == 5 and bday.day >= 21 or bday.month == 6 and bday.day < 21:
return 'gemini'
if bday.month == 6 and bday.day >= 21 or bday.month == 7 and bday.day < 22:
return 'cancer'
if bday.month == 7 and bday.day >= 22 or bday.month == 8 and bday.day < 23:
return 'leo'
if bday.month == 8 and bday.day >= 23 or bday.month == 9 and bday.day < 23:
return 'virgo'
if bday.month == 9 and bday.day >= 23 or bday.month == 10 and bday.day < 23:
return 'libra'
if bday.month == 10 and bday.day >= 23 or bday.month == 11 and bday.day < 22:
return 'scorpio'
if bday.month == 11 and bday.day >= 22 or bday.month == 12 and bday.day < 22:
return 'sagittarius'
return 'capricorn'
|
More like this
- Template tag - list punctuation for a list of items by shapiromatron 10 months, 2 weeks ago
- JSONRequestMiddleware adds a .json() method to your HttpRequests by cdcarter 10 months, 3 weeks ago
- Serializer factory with Django Rest Framework by julio 1 year, 5 months ago
- Image compression before saving the new model / work with JPG, PNG by Schleidens 1 year, 6 months ago
- Help text hyperlinks by sa2812 1 year, 7 months ago
Comments
Here is a more pythonic version:
#
Great filter macat. Great version willhardy!
#
Please login first before commenting.