irongit

A simpler way to view django projects

DjangoTree/snippets/python.json
82 lines2.2 KBJSON
1{
2 "DjangoTree URLs": {
3 "prefix": "dt-urls",
4 "body": [
5 "from django.urls import path, re_path, include",
6 "from . import views",
7 "",
8 "urlpatterns = [",
9 "$1",
10 "]"
11 ],
12 "description": "Snippet for a Django URLs file"
13 },
14 "DjangoTree Websocket URLs": {
15 "prefix": "dt-ws-urls",
16 "body": [
17 "from django.urls import path, re_path",
18 "from channels.routing import URLRouter",
19 "from . import consumers",
20 "",
21 "websocket_urlpatterns = [",
22 "\t$1",
23 "]"
24 ],
25 "description": "Snippet for a Django Websocket URLs file"
26 },
27 "DjangoTree Command": {
28 "prefix": "dt-command",
29 "body": [
30 "from django.core.management.base import BaseCommand",
31 "",
32 "class Command(BaseCommand):",
33 "\thelp = '$1'",
34 "",
35 "\tdef handle(self, *args, **options):",
36 "\t\t$2"
37 ],
38 "description": "Snippet for a Django management command"
39 },
40 "DjangoTree Serializers": {
41 "prefix": "dt-serializers",
42 "body": [
43 "from rest_framework import serializers",
44 "",
45 "class $1Serializer(serializers.ModelSerializer):",
46 "\tclass Meta:",
47 "\t\tmodel = $2",
48 "\t\tfields = '__all__'"
49 ],
50 "description": "Snippet for a Django REST Framework serializer"
51 },
52 "DjangoTree ViewSet": {
53 "prefix": "dt-viewset",
54 "body": [
55 "from rest_framework import viewsets",
56 "from .models import $1",
57 "from .serializers import $1Serializer",
58 "",
59 "class $1ViewSet(viewsets.ModelViewSet):",
60 "\tqueryset = $1.objects.all()",
61 "\tserializer_class = $1Serializer"
62 ],
63 "description": "Snippet for a Django REST Framework viewset"
64 },
65 "DjangoTree Consumer": {
66 "prefix": "dt-consumer",
67 "body": [
68 "from channels.generic.websocket import AsyncWebsocketConsumer",
69 "",
70 "class ${1:MyConsumer}(AsyncWebsocketConsumer):",
71 "\tasync def connect(self):",
72 "\t\t${2:print('Connected!')}",
73 "",
74 "\tasync def disconnect(self, close_code):",
75 "\t\t${3:print('Disconnected!')}",
76 "",
77 "\tasync def receive(self, text_data):",
78 "\t\t${4:print('Received:', text_data)}"
79 ],
80 "description": "Snippet for a Django Channels consumer"
81 }
82}