Created
July 21, 2013 18:25
-
-
Save robrocker7/6049410 to your computer and use it in GitHub Desktop.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
class Movie(models.Model): | |
title = models.CharField(max_length=500) | |
description = models.CharField(max_length=500, blank=True, default=u"") | |
category = models.CharField(max_length=200, choices=MOVIE_CATEGORIES) | |
aff_url = models.URLField(blank=True, default=u"", max_length=1000) | |
trailer_url = models.URLField(blank=True, default=u"") | |
starring = models.ManyToManyField("pois.Poi", blank=True) | |
price = models.IntegerField(blank=True, default=0) | |
image = models.ImageField(upload_to=partial(get_upload_location, "movie")) | |
releasedate = models.DateField(null=True,blank=True) | |
product_api_id = models.CharField(max_length=36) | |
def __unicode__(self): | |
return self.title | |
def get_absolute_url(self): | |
return reverse('product_page', kwargs={ | |
'title': self.title.lower().replace(' ', '-'), | |
'product_id': self.id, | |
}) | |
def thumb_count(self): | |
return (self.thumb_rating_set.filter(thumb=True).count()) - (self.thumb_rating_set.filter(thumb=False).count()) | |
class Thumb_Rating(models.Model): | |
movie = models.ForeignKey("products.Movie", blank=True) | |
author = models.ForeignKey('auth.User', related_name='author') | |
thumb = models.BooleanField(default=False) | |
def __unicode__(self): | |
return self.author.username | |
def hmr_index(request): | |
movies = Movie.objects.all() | |
user_votes = Thumb_Rating.objects.filter(author=request.user) | |
movies = sorted(Movie.objects.all(), key=lambda a: a.thumb_count(), reverse=True) | |
for movie in movies: | |
movie.user_vote = movie.thumb_rating_set.filter(author=request.user) | |
return render(request, 'hismoviereviews/index.html', dict( | |
movies=movies, | |
user_votes = user_votes, | |
)) | |
{% for movie in movies %} | |
<div href="{{ movie.aff_url }}" title="Buy {{ movie.title }} starring {{ poi.name }} on Amazon {% if movie.price %}for ${{ movie.price }}{% endif %}" class="movie"> | |
<img src="{{ movie.image.url }}" alt="{{ movie.title }}" height="232" /> | |
<h2>{{ movie.user_vote }}</h2> | |
<p class="score"><i class="icon-thumbs-up"></i> {{ movie.thumb_count }}</p> | |
<i class="icon-thumbs-up-alt vote-up {{ movie.user_vote|yesno:'active' }}" data-pk="{{ movie.pk }}" data-thumb="True"></i> | |
<i class="icon-thumbs-down-alt vote-down {% for vote in user_votes %}{% if movie.id == vote.movie.all.0.pk %}{{ vote.thumb|yesno:",active," }}{% endif %}{% endfor %}" data-pk="{{ movie.pk }}" data-thumb="False"></i> | |
</div> | |
{% endfor %} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment