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.
 
 
 
 

39 lines
1.5 KiB

  1. from __future__ import unicode_literals
  2. from django.contrib.sites.models import Site
  3. from django.core.urlresolvers import get_script_prefix
  4. from django.db import models
  5. from django.utils.encoding import iri_to_uri, python_2_unicode_compatible
  6. from django.utils.translation import ugettext_lazy as _
  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=_(
  15. "Example: 'flatpages/contact_page.html'. If this isn't provided, "
  16. "the system will use 'flatpages/default.html'."
  17. ),
  18. )
  19. registration_required = models.BooleanField(_('registration required'),
  20. help_text=_("If this is checked, only logged-in users will be able to view the page."),
  21. default=False)
  22. sites = models.ManyToManyField(Site, verbose_name=_('sites'))
  23. class Meta:
  24. db_table = 'django_flatpage'
  25. verbose_name = _('flat page')
  26. verbose_name_plural = _('flat pages')
  27. ordering = ('url',)
  28. def __str__(self):
  29. return "%s -- %s" % (self.url, self.title)
  30. def get_absolute_url(self):
  31. # Handle script prefix manually because we bypass reverse()
  32. return iri_to_uri(get_script_prefix().rstrip('/') + self.url)