2006-05-02 09:31:56 +08:00
|
|
|
from django.db import models
|
|
|
|
from django.contrib.sites.models import Site
|
Merged Unicode branch into trunk (r4952:5608). This should be fully
backwards compatible for all practical purposes.
Fixed #2391, #2489, #2996, #3322, #3344, #3370, #3406, #3432, #3454, #3492, #3582, #3690, #3878, #3891, #3937, #4039, #4141, #4227, #4286, #4291, #4300, #4452, #4702
git-svn-id: http://code.djangoproject.com/svn/django/trunk@5609 bcc190cf-cafb-0310-a4f2-bffc1f526a37
2007-07-04 20:11:04 +08:00
|
|
|
from django.utils.translation import ugettext_lazy as _
|
2005-11-11 12:45:05 +08:00
|
|
|
|
2006-05-02 09:31:56 +08:00
|
|
|
class Redirect(models.Model):
|
2008-07-19 07:54:34 +08:00
|
|
|
site = models.ForeignKey(Site)
|
2007-08-05 13:14:46 +08:00
|
|
|
old_path = models.CharField(_('redirect from'), max_length=200, db_index=True,
|
2005-11-11 12:45:05 +08:00
|
|
|
help_text=_("This should be an absolute path, excluding the domain name. Example: '/events/search/'."))
|
2007-08-05 13:14:46 +08:00
|
|
|
new_path = models.CharField(_('redirect to'), max_length=200, blank=True,
|
2005-11-11 12:45:05 +08:00
|
|
|
help_text=_("This can be either an absolute path (as above) or a full URL starting with 'http://'."))
|
2006-06-13 00:20:05 +08:00
|
|
|
|
2006-05-02 09:31:56 +08:00
|
|
|
class Meta:
|
2005-11-11 12:45:05 +08:00
|
|
|
verbose_name = _('redirect')
|
|
|
|
verbose_name_plural = _('redirects')
|
2006-05-02 09:31:56 +08:00
|
|
|
db_table = 'django_redirect'
|
2005-11-11 12:45:05 +08:00
|
|
|
unique_together=(('site', 'old_path'),)
|
|
|
|
ordering = ('old_path',)
|
2008-07-19 07:54:34 +08:00
|
|
|
|
|
|
|
def __unicode__(self):
|
|
|
|
return "%s ---> %s" % (self.old_path, self.new_path)
|
2006-06-13 00:20:05 +08:00
|
|
|
|
2008-07-19 07:54:34 +08:00
|
|
|
# Register the admin options for these models.
|
|
|
|
# TODO: Maybe this should live in a separate module admin.py, but how would we
|
|
|
|
# ensure that module was loaded?
|
|
|
|
|
|
|
|
from django.contrib import admin
|
|
|
|
|
|
|
|
class RedirectAdmin(admin.ModelAdmin):
|
|
|
|
list_display = ('old_path', 'new_path')
|
|
|
|
list_filter = ('site',)
|
|
|
|
search_fields = ('old_path', 'new_path')
|
|
|
|
radio_fields = {'site': admin.VERTICAL}
|
|
|
|
|
|
|
|
admin.site.register(Redirect, RedirectAdmin)
|
2005-11-11 12:45:05 +08:00
|
|
|
|