| 1 |
from django.contrib.sites.models import Site |
| 2 |
from django.db import models |
| 3 |
from django.utils.translation import gettext_lazy as _ |
| 4 |
|
| 5 |
|
| 6 |
class Redirect(models.Model): |
| 7 |
site = models.ForeignKey(Site, models.CASCADE, verbose_name=_("site")) |
| 8 |
old_path = models.CharField( |
| 9 |
_("redirect from"), |
| 10 |
max_length=200, |
| 11 |
db_index=True, |
| 12 |
help_text=_( |
| 13 |
"This should be an absolute path, excluding the domain name. Example: " |
| 14 |
"“/events/search/”." |
| 15 |
), |
| 16 |
) |
| 17 |
new_path = models.CharField( |
| 18 |
_("redirect to"), |
| 19 |
max_length=200, |
| 20 |
blank=True, |
| 21 |
help_text=_( |
| 22 |
"This can be either an absolute path (as above) or a full URL " |
| 23 |
"starting with a scheme such as “https://”." |
| 24 |
), |
| 25 |
) |
| 26 |
|
| 27 |
class Meta: |
| 28 |
verbose_name = _("redirect") |
| 29 |
verbose_name_plural = _("redirects") |
| 30 |
db_table = "django_redirect" |
| 31 |
unique_together = [["site", "old_path"]] |
| 32 |
ordering = ["old_path"] |
| 33 |
|
| 34 |
def __str__(self): |
| 35 |
return "%s ---> %s" % (self.old_path, self.new_path) |