You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

models.py 985B

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