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 1.4KB

12345678910111213141516171819202122232425262728293031323334353637383940
  1. from django.contrib.sites.models import Site
  2. from django.db import models
  3. from django.urls import get_script_prefix
  4. from django.utils.encoding import iri_to_uri
  5. from django.utils.translation import gettext_lazy as _
  6. class FlatPage(models.Model):
  7. url = models.CharField(_('URL'), max_length=100, db_index=True)
  8. title = models.CharField(_('title'), max_length=200)
  9. content = models.TextField(_('content'), blank=True)
  10. enable_comments = models.BooleanField(_('enable comments'), default=False)
  11. template_name = models.CharField(
  12. _('template name'),
  13. max_length=70,
  14. blank=True,
  15. help_text=_(
  16. "Example: 'flatpages/contact_page.html'. If this isn't provided, "
  17. "the system will use 'flatpages/default.html'."
  18. ),
  19. )
  20. registration_required = models.BooleanField(
  21. _('registration required'),
  22. help_text=_("If this is checked, only logged-in users will be able to view the page."),
  23. default=False,
  24. )
  25. sites = models.ManyToManyField(Site, verbose_name=_('sites'))
  26. class Meta:
  27. db_table = 'django_flatpage'
  28. verbose_name = _('flat page')
  29. verbose_name_plural = _('flat pages')
  30. ordering = ('url',)
  31. def __str__(self):
  32. return "%s -- %s" % (self.url, self.title)
  33. def get_absolute_url(self):
  34. # Handle script prefix manually because we bypass reverse()
  35. return iri_to_uri(get_script_prefix().rstrip('/') + self.url)