Merge branch 'feature/news-rating' into 'develop'
Feature/news rating See merge request gm/gm-backend!47
This commit is contained in:
commit
cc51e36457
22
apps/rating/migrations/0002_auto_20191004_0928.py
Normal file
22
apps/rating/migrations/0002_auto_20191004_0928.py
Normal file
|
|
@ -0,0 +1,22 @@
|
||||||
|
# Generated by Django 2.2.4 on 2019-10-04 09:28
|
||||||
|
|
||||||
|
from django.db import migrations
|
||||||
|
|
||||||
|
|
||||||
|
class Migration(migrations.Migration):
|
||||||
|
|
||||||
|
dependencies = [
|
||||||
|
('contenttypes', '0002_remove_content_type_name'),
|
||||||
|
('rating', '0001_initial'),
|
||||||
|
]
|
||||||
|
|
||||||
|
operations = [
|
||||||
|
migrations.AlterModelOptions(
|
||||||
|
name='rating',
|
||||||
|
options={},
|
||||||
|
),
|
||||||
|
migrations.AlterUniqueTogether(
|
||||||
|
name='rating',
|
||||||
|
unique_together={('ip', 'object_id', 'content_type')},
|
||||||
|
),
|
||||||
|
]
|
||||||
|
|
@ -10,6 +10,9 @@ class Rating(models.Model):
|
||||||
content_object = GenericForeignKey('content_type', 'object_id')
|
content_object = GenericForeignKey('content_type', 'object_id')
|
||||||
ip = models.GenericIPAddressField(verbose_name=_('ip'))
|
ip = models.GenericIPAddressField(verbose_name=_('ip'))
|
||||||
|
|
||||||
|
class Meta:
|
||||||
|
unique_together = ('ip', 'object_id', 'content_type')
|
||||||
|
|
||||||
@property
|
@property
|
||||||
def name(self):
|
def name(self):
|
||||||
# Check if Generic obj has name or title
|
# Check if Generic obj has name or title
|
||||||
|
|
|
||||||
|
|
@ -1,5 +1,4 @@
|
||||||
from datetime import timedelta
|
from celery import shared_task
|
||||||
from celery import task
|
|
||||||
from rating.models import Rating
|
from rating.models import Rating
|
||||||
from django.contrib.contenttypes.models import ContentType
|
from django.contrib.contenttypes.models import ContentType
|
||||||
|
|
||||||
|
|
@ -10,13 +9,10 @@ def add_rating(remote_addr, pk, model, app_label):
|
||||||
)
|
)
|
||||||
|
|
||||||
|
|
||||||
@task
|
@shared_task
|
||||||
def add(remote_addr, pk, model, app_label):
|
def add(remote_addr, pk, model, app_label):
|
||||||
rating = Rating()
|
content_type = ContentType.objects.get(app_label=app_label, model=model)
|
||||||
rating.ip = remote_addr
|
Rating.objects.get_or_create(
|
||||||
rating.object_id = pk
|
ip=remote_addr, object_id=pk, content_type=content_type)
|
||||||
rating.content_type = ContentType.objects.get(app_label=app_label, model=model)
|
|
||||||
rating.save()
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
|
||||||
Loading…
Reference in New Issue
Block a user