app/django/contrib/flatpages/models.py
changeset 323 ff1a9aa48cfd
parent 54 03e267d67478
equal deleted inserted replaced
322:6641e941ef1e 323:ff1a9aa48cfd
     1 from django.core import validators
       
     2 from django.db import models
     1 from django.db import models
     3 from django.contrib.sites.models import Site
     2 from django.contrib.sites.models import Site
     4 from django.utils.translation import ugettext_lazy as _
     3 from django.utils.translation import ugettext_lazy as _
     5 
     4 
     6 
     5 
     7 class FlatPage(models.Model):
     6 class FlatPage(models.Model):
     8     url = models.CharField(_('URL'), max_length=100, validator_list=[validators.isAlphaNumericURL], db_index=True,
     7     url = models.CharField(_('URL'), max_length=100, db_index=True)
     9         help_text=_("Example: '/about/contact/'. Make sure to have leading and trailing slashes."))
       
    10     title = models.CharField(_('title'), max_length=200)
     8     title = models.CharField(_('title'), max_length=200)
    11     content = models.TextField(_('content'))
     9     content = models.TextField(_('content'), blank=True)
    12     enable_comments = models.BooleanField(_('enable comments'))
    10     enable_comments = models.BooleanField(_('enable comments'))
    13     template_name = models.CharField(_('template name'), max_length=70, blank=True,
    11     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'."))
    12         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'), help_text=_("If this is checked, only logged-in users will be able to view the page."))
    13     registration_required = models.BooleanField(_('registration required'), help_text=_("If this is checked, only logged-in users will be able to view the page."))
    16     sites = models.ManyToManyField(Site)
    14     sites = models.ManyToManyField(Site)
    19         db_table = 'django_flatpage'
    17         db_table = 'django_flatpage'
    20         verbose_name = _('flat page')
    18         verbose_name = _('flat page')
    21         verbose_name_plural = _('flat pages')
    19         verbose_name_plural = _('flat pages')
    22         ordering = ('url',)
    20         ordering = ('url',)
    23 
    21 
    24     class Admin:
       
    25         fields = (
       
    26             (None, {'fields': ('url', 'title', 'content', 'sites')}),
       
    27             (_('Advanced options'), {'classes': 'collapse', 'fields': ('enable_comments', 'registration_required', 'template_name')}),
       
    28         )
       
    29         list_filter = ('sites',)
       
    30         search_fields = ('url', 'title')
       
    31 
       
    32     def __unicode__(self):
    22     def __unicode__(self):
    33         return u"%s -- %s" % (self.url, self.title)
    23         return u"%s -- %s" % (self.url, self.title)
    34 
    24 
    35     def get_absolute_url(self):
    25     def get_absolute_url(self):
    36         return self.url
    26         return self.url