SHARE
TWEET

Untitled

a guest Feb 17th, 2017 47 Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1. class Post(models.Model):
  2.     poster = models.ForeignKey('auth.User')
  3.     question = models.ForeignKey('self', null=True, blank=True)
  4.     post_title = models.CharField(max_length=300)
  5.     post_content = models.TextField(null=True, blank=True)
  6.  
  7.     is_published = models.BooleanField(default=True)
  8.     is_locked = models.BooleanField(default=False)
  9.     is_question = models.BooleanField(default=True)
  10.     is_deleted = models.BooleanField(default=False)
  11.  
  12.     created_date = models.DateTimeField(
  13.             default=timezone.now)
  14.     published_date = models.DateTimeField(
  15.             blank=True, null=True)
  16.     date_modified = models.DateTimeField(
  17.             blank=True, null=True)
  18.  
  19.     def publish(self):
  20.         self.published_date = timezone.now()
  21.         self.save()
  22.  
  23.     def __str__(self):
  24.         return self.post_title
  25.  
  26. class Vote(models.Model):
  27.     user = models.ForeignKey('auth.User')
  28.     post = models.ForeignKey('Post')
  29.     vote_type = models.SmallIntegerField()#-1, 0, 1
  30.     date_voted = models.DateTimeField(
  31.             default=timezone.now)
  32.     def __str__(self):
  33.         return self.user
  34.    
  35. def index(request):
  36.     posts = Post.objects.filter(created_date__lte=timezone.now(
  37.     ), is_question=1, is_published=1).order_by('-created_date')
  38.     #removed the paging stuff here for simplification
  39.     return render(request, 'homepage/index.html', {'posts': posts})
  40.    
  41. {% for post in posts %}
  42.        {{ post|total_votes|default:"0" }}
  43.     {% endfor %}
RAW Paste Data
Top