Changeset 6 for bitstructures/trunk/substructure/models.py
- Timestamp:
- 09/17/07 18:48:54 (16 months ago)
- Files:
-
- 1 modified
-
bitstructures/trunk/substructure/models.py (modified) (3 diffs)
Legend:
- Unmodified
- Added
- Removed
-
bitstructures/trunk/substructure/models.py
r2 r6 7 7 >>> test1.id = 1 8 8 >>> test1.slug = 'testentry1' 9 >>> bool(test1.date)9 >>> test1.is_published() 10 10 False 11 >>> bool(test1.is_public)12 False11 >>> test1.is_draft() 12 True 13 13 >>> test1.get_absolute_url() 14 '/ testentry1'14 '/drafts/testentry1' 15 15 >>> test2 = Entry() 16 16 >>> test2.id = 2 17 17 >>> test2.slug = 'testentry2' 18 >>> test2.date = datetime(2001, 2, 3)19 >>> bool(test2.date)18 >>> test2.date_published = datetime(2001, 2, 3) 19 >>> test2.is_published() 20 20 True 21 >>> bool(test2.is_public)21 >>> test2.is_draft() 22 22 False 23 23 >>> test2.get_absolute_url() … … 27 27 slug = models.SlugField(unique=True, blank=False) 28 28 title = models.CharField(maxlength=200, blank=False) 29 date = models.DateTimeField(null=True, blank=True) 30 is_public = models.BooleanField() 29 date_published = models.DateTimeField(null=True, blank=True) 31 30 text = models.TextField(blank=False) 32 31 … … 34 33 return self.title 35 34 35 def is_published(self): 36 return bool(self.date_published) 37 38 def is_draft(self): 39 return not self.is_published() 40 36 41 def get_absolute_url(self): 37 if self. date:38 year = self.date .year39 month = self.date .month42 if self.is_published(): 43 year = self.date_published.year 44 month = self.date_published.month 40 45 return '/%04d/%02d/%s' % (year, month, self.slug) 41 46 else: 42 return '/ %s' % (self.slug)47 return '/drafts/%s' % (self.slug) 43 48 44 49 class Admin: 45 50 fields = ( 46 (None, {'fields': ('title', 'slug', 'date ', 'is_public')}),51 (None, {'fields': ('title', 'slug', 'date_published')}), 47 52 (None, {'fields': ('text',), 'classes': 'monospace'}) 48 53 ) 49 list_display = ('title', ' slug', 'date', 'is_public', 'get_absolute_url')50 ordering = ['-date ']54 list_display = ('title', 'get_absolute_url', 'date_published') 55 ordering = ['-date_published']
