from django.db import models
from django.db.models import F
# from django.contrib.auth.models import User
class Video(models.Model):
video = models.FileField(upload_to='video/%Y/%m/%d')
rating = models.IntegerField(default=0)
@classmethod
def change_rating(cls, pk, value):
webm = cls.objects.get(pk=pk)
webm.rating = F('rating' + value)
webm.save()
@classmethod
def increment_rating(cls, pk):
cls.change_rating(pk, 1)
@classmethod
def decrease_rating(cls, pk):
cls.change_rating(pk, -1)
ZnJvbSBkamFuZ28uZGIgaW1wb3J0IG1vZGVscwpmcm9tIGRqYW5nby5kYi5tb2RlbHMgaW1wb3J0IEYKIyBmcm9tIGRqYW5nby5jb250cmliLmF1dGgubW9kZWxzIGltcG9ydCBVc2VyCgoKY2xhc3MgVmlkZW8obW9kZWxzLk1vZGVsKToKICAgIHZpZGVvID0gbW9kZWxzLkZpbGVGaWVsZCh1cGxvYWRfdG89J3ZpZGVvLyVZLyVtLyVkJykKICAgIHJhdGluZyA9IG1vZGVscy5JbnRlZ2VyRmllbGQoZGVmYXVsdD0wKQoKICAgIEBjbGFzc21ldGhvZAogICAgZGVmIGNoYW5nZV9yYXRpbmcoY2xzLCBwaywgdmFsdWUpOgogICAgICAgIHdlYm0gPSBjbHMub2JqZWN0cy5nZXQocGs9cGspCiAgICAgICAgd2VibS5yYXRpbmcgPSBGKCdyYXRpbmcnICsgdmFsdWUpCiAgICAgICAgd2VibS5zYXZlKCkKCiAgICBAY2xhc3NtZXRob2QKICAgIGRlZiBpbmNyZW1lbnRfcmF0aW5nKGNscywgcGspOgogICAgICAgIGNscy5jaGFuZ2VfcmF0aW5nKHBrLCAxKQoKICAgIEBjbGFzc21ldGhvZAogICAgZGVmIGRlY3JlYXNlX3JhdGluZyhjbHMsIHBrKToKICAgICAgICBjbHMuY2hhbmdlX3JhdGluZyhwaywgLTEpCg==