Files
social-graph/backend/contacts/views.py
T
gitrusprusandCursor cafc7335ad Add plugin platform with modular backend and frontend registry.
Split graph/import/meta into Django apps, add API v1 with OpenAPI and pytest, and introduce plugin registry with the tags reference plugin on both FE and BE.

Co-authored-by: Cursor <cursoragent@cursor.com>
2026-06-25 09:35:51 +03:00

46 lines
1.3 KiB
Python

from rest_framework import viewsets
from .models import Contact, Relation, NetworkMap, NetworkMapMembership
from .serializers import (
ContactSerializer,
RelationSerializer,
NetworkMapSerializer,
NetworkMapMembershipSerializer,
)
class ContactViewSet(viewsets.ModelViewSet):
queryset = Contact.objects.all()
serializer_class = ContactSerializer
def get_queryset(self):
qs = super().get_queryset()
q = self.request.query_params.get('search', '')
if q:
qs = qs.filter(name__icontains=q)
return qs
class RelationViewSet(viewsets.ModelViewSet):
queryset = Relation.objects.select_related('source', 'target').all()
serializer_class = RelationSerializer
class NetworkMapViewSet(viewsets.ModelViewSet):
queryset = NetworkMap.objects.all()
serializer_class = NetworkMapSerializer
class NetworkMapMembershipViewSet(viewsets.ModelViewSet):
serializer_class = NetworkMapMembershipSerializer
def get_queryset(self):
map_id = self.kwargs.get('map_pk')
return NetworkMapMembership.objects.filter(
map_id=map_id
).select_related('contact', 'map')
def perform_create(self, serializer):
map_id = self.kwargs.get('map_pk')
serializer.save(map_id=map_id)