You can not select more than 25 topics
Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
29 lines
979 B
29 lines
979 B
from django.db.models.signals import post_save
|
|
from django.dispatch import receiver
|
|
|
|
from ratings.models import HistoryRating
|
|
from .models import Review
|
|
|
|
|
|
@receiver(post_save, sender=Review)
|
|
def add_rating_review(sender, instance, created, **kwargs):
|
|
hs_rating = HistoryRating()
|
|
if instance.target_team:
|
|
hs_rating.team = instance.target_team
|
|
elif instance.target_contractor or instance.target_customer:
|
|
hs_rating.user = instance.target_contractor or instance.target_customer
|
|
|
|
if instance.type == 'positive':
|
|
hs_rating.rating = 1
|
|
elif instance.type == 'negative':
|
|
hs_rating.rating = -1
|
|
else:
|
|
hs_rating = 0
|
|
hs_rating.description = 'Изменения рейтинга после отзыва'
|
|
hs_rating.save()
|
|
|
|
count_reviews = Review.objects.filter(project=instance.project).count()
|
|
if count_reviews == 2:
|
|
order = instance.project.order
|
|
order.status = 'completed'
|
|
order.save()
|
|
|