Неподдерживаемые типы операндов 'Decimal128' и 'decimal.Decimal' | (django)
Я начал проект на Django и только что переключил локальную базу данных SQLite на mongodb. Теперь, когда я пытаюсь протестировать функциональность сайта, я получаю непонятные ошибки. Например, когда я хочу просмотреть все свои данные по определенному курсу и отправляю все данные обратно в HTML, я получаю ошибку:
unsupported operand type(s) for /: 'Decimal128' and 'decimal.Decimal'
я использую звездный рейтинг django, поэтому у меня также есть этот пакет в моих html файлах, смотрите ниже, как я загружаю рейтинг obj.
Ошибки терминала:
Думаю, проблема в этой строке
'percentage': 100 * (rating.average / Decimal(app_settings.STAR_RATINGS_RANGE)),
app_settings.STAR_RATINGS_RANGE равно 5
файл rating.py:
from __future__ import unicode_literals
from decimal import Decimal
import uuid
from django import template
from django.template import loader
from django.templatetags.static import static
from ..models import UserRating
from .. import app_settings, get_star_ratings_rating_model
from ..compat import is_authenticated
register = template.Library()
@register.simple_tag(takes_context=True)
def ratings(context, item, icon_height=app_settings.STAR_RATINGS_STAR_HEIGHT, icon_width=app_settings.STAR_RATINGS_STAR_WIDTH, read_only=False, template_name=None):
request = context.get('request')
if request is None:
raise Exception('Make sure you have "django.core.context_processors.request" in your templates context processor list')
rating = get_star_ratings_rating_model().objects.for_instance(item)
user = is_authenticated(request.user) and request.user or None
if is_authenticated(request.user) or app_settings.STAR_RATINGS_ANONYMOUS:
user_rating = UserRating.objects.for_instance_by_user(item, user=user)
else:
user_rating = None
if user_rating is not None:
user_rating_percentage = 100 * (user_rating.score / Decimal(app_settings.STAR_RATINGS_RANGE))
else:
user_rating_percentage = None
stars = [i for i in range(1, app_settings.STAR_RATINGS_RANGE + 1)]
# We get the template to load here rather than using inclusion_tag so that the
# template name can be passed as a template parameter
template_name = template_name or context.get('star_ratings_template_name') or 'star_ratings/widget.html'
return loader.get_template(template_name).render({
'rating': rating,
'request': request,
'user': request.user,
'user_rating': user_rating,
'user_rating_percentage': user_rating_percentage,
'stars': stars,
'star_count': app_settings.STAR_RATINGS_RANGE,
'percentage': 100 * (rating.average / Decimal(app_settings.STAR_RATINGS_RANGE)),
'icon_height': icon_height,
'icon_width': icon_width,
'sprite_width': icon_width * 3,
'sprite_image': static(app_settings.STAR_RATINGS_STAR_SPRITE),
'id': 'dsr{}'.format(uuid.uuid4().hex),
'anonymous_ratings': app_settings.STAR_RATINGS_ANONYMOUS,
'read_only': read_only,
'editable': not read_only and (is_authenticated(request.user) or app_settings.STAR_RATINGS_ANONYMOUS),
'clearable': not read_only and (is_authenticated(request.user) and app_settings.STAR_RATINGS_CLEARABLE)
}, request=request)
это views.py
class HomeWorksView(View):
def get(self,request,course_id,user_id):
course = Course.objects.get(id=course_id)
homeworks = HomeWork.objects.filter(course=course).iterator()
return render(request,"HomeWorks.html",{'course':course,'homeworks':homeworks})
class VideoView(View):
def get(self, request, course_id):
course = Course.objects.get(id=course_id)
videos = YouTubeVideo.objects.filter(course=course).iterator()
return render(request,"videos.html",{'course':course, 'videos':videos})
На страницах videos.html и HomeWorks.html есть рейтинг. Поэтому, когда я пытаюсь просмотреть одну из страниц, она падает! {% load ratings %}
одна из html-страниц (HomeWorks.html):
