Commit 98522569 authored by adam's avatar adam
parents 63a11fb7 0567d761
......@@ -21,4 +21,11 @@ class Discussion(models.Model):
tag = models.ForeignKey(Tag, related_name='place_of_discussion', blank=False, null=False, default=None)
def __str__(self):
return self.question
\ No newline at end of file
return self.question
def add_message(self, user, text):
message = TextMessage.objects.create()
message.user = user
message.text = text
self.messages.add(message)
self.save()
\ No newline at end of file
# Create your views here.
from django.shortcuts import get_object_or_404
from rest_framework import viewsets, permissions
from rest_framework.decorators import detail_route
from app.API.serializers import APISerializer
from app.Discussion.models import Discussion, TextMessage
from app.Discussion.serializers import TextMessageSerializer, DiscussionSerializer
from rest_framework.response import Response
import rest_framework
class DiscussionViewSet(viewsets.ModelViewSet):
"""
......@@ -13,6 +16,14 @@ class DiscussionViewSet(viewsets.ModelViewSet):
serializer_class = DiscussionSerializer
permission_classes = (permissions.IsAuthenticatedOrReadOnly,)
@detail_route()
def add(self, request, pk=None):
discussion = get_object_or_404(self.queryset, pk=pk)
text = request.data.get('text')
user = request.user
discussion.add_message(text=text, user=user)
return Response(status=rest_framework.status.HTTP_200_OK)
class TextMessageViewSet(viewsets.ModelViewSet):
"""
API for articles
......
......@@ -29,6 +29,6 @@ class API(BaseAPI):
result['name'] = property['value']
elif property['key'] == 'lat':
result['latitude'] = property['value']
elif property['key'] == 'lon':
elif property['key'] == 'lng':
result['longitude'] = property['value']
return result
\ No newline at end of file
......@@ -31,4 +31,12 @@ class API(BaseAPI):
result['latitude'] = property['value']
elif property['key'] == 'OADR_GPS_D':
result['longitude'] = property['value']
elif property['key'] == 'OADR_MIASTO':
result['city'] = property['value']
elif property['key'] == 'OADR_ULICA':
result['street'] = property['value']
elif property['key'] == 'OADR_NR':
result['nr'] = property['value']
result['address'] = "{0} {1}, {2}".format(result['street'].encode("utf-8"), result['nr'].encode("utf-8"), result['city'].encode("utf-8"))
return result
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment