# -*- coding: utf-8 -*- from django.db import models from hvad.models import TranslatableModel, TranslatedFields from django.contrib.contenttypes.models import ContentType from django.contrib.contenttypes import generic from django.utils.translation import ugettext as _ class Review(models.Model): """ Create Review model Uses ContentType for connection Review with another models content_type = model which linked Review object object_id = specific object of model which linked Review object """ #connection with models content_type = models.ForeignKey(ContentType, null=True) object_id = models.PositiveIntegerField(blank=True, null=True) object = generic.GenericForeignKey(content_type, object_id) user = models.ForeignKey('accounts.User', blank=True, null=True, on_delete=models.PROTECT, related_name='reviews') comment = models.TextField(verbose_name=_(u'Отзыв')) rating = models.SmallIntegerField(verbose_name=_(u'Оценка'), blank=True, null=True) #field saves information about creating and changing model created = models.DateTimeField(auto_now_add=True) modified = models.DateTimeField(auto_now=True) def __unicode__(self): return self.comment