def get_or_create_object(self): me = Friend.objects.filter(me=True).first() if not me: x = Friend.random_position() y = Friend.random_position() me = Friend(x=x, y=y, me=True) me.save() me.generate_friends() return me
def get(self, request): Friend.objects.all().delete() x = Friend.random_position() y = Friend.random_position() me = Friend(x=x, y=y, me=True) me.save() me.generate_friends() me_serialized = FriendSerializer(me) return Response(me_serialized.data)