models.py 1.5 KB

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