Created
June 16, 2010 20:37
-
-
Save codekoala/441233 to your computer and use it in GitHub Desktop.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| # ---- some file that is processed early in Django's execution (like a urls.py or __init__.py file) | |
| from product.models import ProductManager | |
| def deal_o_day(self): | |
| """Determines which product is the current Deal of the Day""" | |
| return self.filter(stuff_in_stock__gt=0, foo=bar) | |
| ProductManager.deal_o_day = deal_o_day | |
| # ---- middleware.py | |
| from django.http import HttpResponseRedirect | |
| from product.models import Product | |
| class DealODayMiddleware(object): | |
| def process_request(self, request): | |
| """Redirects users to the product detail page for the deal of the day when they access the site root""" | |
| if request.path == '/': | |
| product = Product.objects.deal_o_day() | |
| return HttpResponseRedirect(product.get_absolute_url()) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment