diff options
Diffstat (limited to 'src/testapp/models.py')
| -rw-r--r-- | src/testapp/models.py | 97 |
1 files changed, 62 insertions, 35 deletions
diff --git a/src/testapp/models.py b/src/testapp/models.py index 3960d004..32d9a612 100644 --- a/src/testapp/models.py +++ b/src/testapp/models.py @@ -1,63 +1,90 @@ from django.db import models from django.template.defaultfilters import slugify -from datetime import datetime import uuid def uuid_str(): return str(uuid.uuid1()) -class ExampleModel(models.Model): - num = models.IntegerField(default=2, choices=((1,'one'), (2, 'two'))) - hidden_num = models.IntegerField(verbose_name='Something', help_text='HELP') - text = models.TextField(blank=False) - another = models.CharField(max_length=10) +#class ExampleModel(models.Model): +# num = models.IntegerField(default=2, choices=((1,'one'), (2, 'two'))) +# hidden_num = models.IntegerField(verbose_name='Something', help_text='HELP') +# text = models.TextField(blank=False) +# another = models.CharField(max_length=10) -class ExampleContainer(models.Model): - """Container. Has a key, a name, and some internal data, and contains a set of items.""" - key = models.CharField(primary_key=True, default=uuid_str, max_length=36, editable=False) - name = models.CharField(max_length=256) - internal = models.IntegerField(default=0) +#class ExampleContainer(models.Model): +# """Container. Has a key, a name, and some internal data, and contains a set of items.""" +# key = models.CharField(primary_key=True, default=uuid_str, max_length=36, editable=False) +# name = models.CharField(max_length=256) +# internal = models.IntegerField(default=0) + +# @models.permalink +# def get_absolute_url(self): +# return ('testapp.views.ContainerInstance', [self.key]) - @models.permalink - def get_absolute_url(self): - return ('testapp.views.ContainerInstance', [self.key]) +#class ExampleItem(models.Model): +# """Item. Belongs to a container and has an index number and a note. +# Items are uniquely identified by their container and index number.""" +# container = models.ForeignKey(ExampleContainer, related_name='items') +# index = models.IntegerField() +# note = models.CharField(max_length=1024) +# unique_together = (container, index) -class ExampleItem(models.Model): - """Item. Belongs to a container and has an index number and a note. - Items are uniquely identified by their container and index number.""" - container = models.ForeignKey(ExampleContainer, related_name='items') - index = models.IntegerField() - note = models.CharField(max_length=1024) - unique_together = (container, index) +RATING_CHOICES = ((0, 'Awful'), + (1, 'Poor'), + (2, 'OK'), + (3, 'Good'), + (4, 'Excellent')) class BlogPost(models.Model): - slug = models.SlugField(editable=False, primary_key=True, default='blah') - title = models.CharField(max_length=128) - content = models.TextField() - when = models.DateTimeField(editable=False) + key = models.CharField(primary_key=True, max_length=64, default=uuid_str, editable=False) + title = models.CharField(max_length=128, help_text='The article title (Required)') + content = models.TextField(help_text='The article body (Required)') + created = models.DateTimeField(auto_now_add=True) + slug = models.SlugField(editable=False, default='') + + class Meta: + ordering = ('created',) @models.permalink def get_absolute_url(self): - return ('testapp.views.BlogPostInstance', (self.slug,)) + return ('testapp.views.BlogPostInstance', (self.key,)) + + @property + @models.permalink + def comments_url(self): + """Link to a resource which lists all comments for this blog post.""" + return ('testapp.views.CommentList', (self.key,)) + + @property + @models.permalink + def comment_url(self): + """Link to a resource which can create a comment for this blog post.""" + return ('testapp.views.CommentCreator', (self.key,)) + + def __unicode__(self): + return self.title def save(self, *args, **kwargs): self.slug = slugify(self.title) - self.when = datetime.now() super(self.__class__, self).save(*args, **kwargs) class Comment(models.Model): - blogpost = models.ForeignKey(BlogPost, related_name='comments') - name = models.CharField(max_length=128) - content = models.TextField() - when = models.DateTimeField(auto_now_add=True) + blogpost = models.ForeignKey(BlogPost, editable=False, related_name='comments') + username = models.CharField(max_length=128, help_text='Please enter a username (Required)') + comment = models.TextField(help_text='Enter your comment here (Required)') + rating = models.IntegerField(blank=True, null=True, choices=RATING_CHOICES, help_text='Please rate the blog post (Optional)') + created = models.DateTimeField(auto_now_add=True) @models.permalink def get_absolute_url(self): - return ('testapp.views.CommentInstance', (self.blogpost.slug, self.id)) - - def save(self): - self.index = self.blogpost.comments.count()
\ No newline at end of file + return ('testapp.views.CommentInstance', (self.blogpost.key, self.id)) + + @property + @models.permalink + def blogpost_url(self): + return ('testapp.views.BlogPostInstance', (self.blogpost.key,)) + |
