This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
key = self.request.query_params.get('key', None) | |
try: | |
return BusinessTeamMember.objects.get(activation_key=key) | |
except BusinessTeamMember.DoesNotExist: | |
raise Exception('Activation key not found') |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
from rest_framework import parsers, serializers | |
from rest_framework.generics import CreateAPIView | |
from django.contrib.auth import authenticate | |
from rest_framework.authtoken.models import Token | |
class LoginSerializer(serializers.Serializer): | |
email = serializers.CharField(write_only=True) | |
password = serializers.CharField(write_only=True) | |
token = serializers.CharField(read_only=True) |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
{ | |
"conversation_id_1": true, | |
"conversation_id_2: true, | |
} |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
{ | |
"conversation_id_1": true, | |
"conversation_id_2": true | |
} |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
from django.db import models | |
class Note(models.Model): | |
# both these fields can be empty when you create a new note for the first time | |
title = models.CharField(max_length=255, null=True, blank=True) | |
content = models.TextField(null=True, blank=True) | |
# notes will be sorted using this field | |
last_udpated_on = models.DateTimeField(auto_now=True) |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
# Step 1: create a python3 virtual environment called django_env | |
python3 -m venv django_env | |
# Step 2: Activate the virtual environment | |
source django_env/bin/activate | |
# Step 3: Install all the dependencies. | |
pip install django | |
pip install djangorestframework |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
python manage.py makemigrations | |
python manage.py migrate |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
from rest_framework import serializers | |
from .models import Note | |
class NoteSerializer(serializers.ModelSerializer): | |
is_active = serializers.BooleanField(read_only=True) | |
class Meta: | |
model = Note | |
fields = ('id', 'title', 'content', 'last_udpated_on', 'is_active') |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
from django.shortcuts import render, get_object_or_404 | |
from rest_framework.viewsets import ModelViewSet | |
from .models import Note | |
from .serializers import NoteSerializer | |
class NoteViewSet(ModelViewSet): | |
serializer_class = NoteSerializer |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
from django.contrib import admin | |
from django.urls import path | |
from notes.views import NoteViewSet | |
from django.conf.urls import url | |
urlpatterns = [ | |
# the admin path is present by default when you create the Django profject. It is used to access the Django admin panel. | |
path('admin/', admin.site.urls), | |
# the URLs for your APIs start from here |