Add get method in view
This commit is contained in:
parent
7b18d7e430
commit
f0001eef93
|
|
@ -34,6 +34,14 @@ class NewsDetailView(NewsMixinView, generics.RetrieveAPIView):
|
||||||
"""Override get_queryset method."""
|
"""Override get_queryset method."""
|
||||||
return super().get_queryset().with_extended_related()
|
return super().get_queryset().with_extended_related()
|
||||||
|
|
||||||
|
def get(self, request, *args, **kwargs):
|
||||||
|
from rating.tasks import add_rating
|
||||||
|
print('SLUG')
|
||||||
|
add_rating.apply_async(
|
||||||
|
(1, '192.1.1.1.'), countdown=4
|
||||||
|
)
|
||||||
|
return self.retrieve(request, *args, **kwargs)
|
||||||
|
|
||||||
|
|
||||||
class NewsTypeListView(generics.ListAPIView):
|
class NewsTypeListView(generics.ListAPIView):
|
||||||
"""NewsType list view."""
|
"""NewsType list view."""
|
||||||
|
|
|
||||||
|
|
@ -1,5 +1,11 @@
|
||||||
from django.contrib import admin
|
from django.contrib import admin
|
||||||
from rating import models
|
from rating import models
|
||||||
|
from rating import tasks
|
||||||
|
|
||||||
|
#
|
||||||
|
# def add_task_action(modeladmin, request, queryset):
|
||||||
|
# # 1, "192.168.1.1"
|
||||||
|
# tasks.add.delay(1, "192.168.1.1")
|
||||||
|
|
||||||
|
|
||||||
@admin.register(models.Rating)
|
@admin.register(models.Rating)
|
||||||
|
|
@ -7,3 +13,6 @@ class RatingAdmin(admin.ModelAdmin):
|
||||||
"""Rating type admin conf."""
|
"""Rating type admin conf."""
|
||||||
list_display = ['name', 'ip']
|
list_display = ['name', 'ip']
|
||||||
list_display_links = ['name']
|
list_display_links = ['name']
|
||||||
|
# actions = [add_task_action]
|
||||||
|
|
||||||
|
|
||||||
|
|
|
||||||
14
apps/rating/send.py
Normal file
14
apps/rating/send.py
Normal file
|
|
@ -0,0 +1,14 @@
|
||||||
|
from pika import BlockingConnection, ConnectionParameters
|
||||||
|
|
||||||
|
|
||||||
|
def mess():
|
||||||
|
connection = BlockingConnection(ConnectionParameters('rabbitmq'))
|
||||||
|
channel = connection.channel()
|
||||||
|
|
||||||
|
channel.queue_declare(queue='rating')
|
||||||
|
channel.basic_publish(
|
||||||
|
exchange='',
|
||||||
|
routing_key='rating',
|
||||||
|
body='{news_id:127.0.0.1}'
|
||||||
|
)
|
||||||
|
connection.close()
|
||||||
14
apps/rating/tasks.py
Normal file
14
apps/rating/tasks.py
Normal file
|
|
@ -0,0 +1,14 @@
|
||||||
|
from datetime import timedelta
|
||||||
|
from celery.task import periodic_task, Task
|
||||||
|
from celery import task
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
@task
|
||||||
|
def add_rating(object_id, ip):
|
||||||
|
print('object_id: ' + str(object_id))
|
||||||
|
print('ip: ' + str(ip))
|
||||||
|
|
||||||
|
|
||||||
Loading…
Reference in New Issue
Block a user