<commit_before>from django.db import models

from apps.categories.models import Category
from apps.users.models import UserProfile
from apps.reviews.models import Review


class Book(models.Model):
    title = models.CharField(max_length=255)
    slug = models.SlugField(max_length=500)
    author = models.CharField(max_length=255)
    pages = models.IntegerField()
    publish_date = models.DateTimeField()
    description = models.TextField(blank=True, default='')
    categories = models.ManyToManyField(Category, db_table='category_book', related_name='books')
    favourites = models.ManyToManyField(UserProfile, db_table='favourites', related_name='liked_books')

    class Meta:
        db_table = 'book'

    def get_rating(self):
        reviews = Review.objects.filter(book=self)
        rating = 0
        for review in reviews:
            rating += review.rating
        return round(rating / Review.MAX_STARS)


class UserProfileBook(models.Model):
    READING = 1
    READ = 2
    READING_STATUS = (
            (READING, 'Reading'),
            (READ, 'Read'),<commit_msg>Fix get_rating in Book model<commit_after>from django.db import models

from apps.categories.models import Category
from apps.users.models import UserProfile
from apps.reviews.models import Review


class Book(models.Model):
    title = models.CharField(max_length=255)
    slug = models.SlugField(max_length=500)
    author = models.CharField(max_length=255)
    pages = models.IntegerField()
    publish_date = models.DateTimeField()
    description = models.TextField(blank=True, default='')
    categories = models.ManyToManyField(Category, db_table='category_book', related_name='books')
    favourites = models.ManyToManyField(UserProfile, db_table='favourites', related_name='liked_books')

    class Meta:
        db_table = 'book'

    def get_rating(self):
        reviews = Review.objects.filter(book=self)
        total = reviews.count()
        rating = 0
        for review in reviews:
            rating += review.rating
        return round(rating / total)


class UserProfileBook(models.Model):
    READING = 1
    READ = 2
    READING_STATUS = (
            (READING, 'Reading'),
            (READ, 'Read'),
{'fraction_non_alphanumeric': 0.1025293586269196, 'fraction_numerical': 0.01084010840108401, 'mean_word_length': 3.43, 'pattern_counts': {'":': 0, '<': 3, '<?xml version=': 0, '>': 3, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 0, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '5589703', 'n_tokens_mistral': 663, 'n_tokens_neox': 633, 'n_words': 143}