{ "mauto": { "prefix": "mauto", "description": "AutoField (mauto) model field", "body": [ "${FIELDNAME} = models.AutoField()" ] }, "mbigint": { "prefix": "mbigint", "description": "BigIntegerField (mbigint) model field", "body": [ "${FIELDNAME} = models.BigIntegerField(${DESCRICAO})" ] }, "mbool": { "prefix": "mbool", "description": "BooleanField (mbool) model field", "body": [ "${FIELDNAME} = models.BooleanField(${DESCRICAO})" ] }, "mchar": { "prefix": "mchar", "description": "CharField (mchar) model field", "body": [ "${FIELDNAME} = models.CharField(${DESCRICAO}, max_length=50)" ] }, "mcoseint": { "prefix": "mcoseint", "description": "CommaSeparatedIntegerField (mcoseint) model field", "body": [ "${FIELDNAME} = models.CommaSeparatedIntegerField(${DESCRICAO})" ] }, "mdate": { "prefix": "mdate", "description": "DateField (mdate) model field", "body": [ "${FIELDNAME} = models.DateField(${DESCRICAO})" ] }, "mdatetime": { "prefix": "mdatetime", "description": "DateTimeField (mdatetime) model field", "body": [ "${FIELDNAME} = models.DateTimeField(${DESCRICAO})" ] }, "mdecimal": { "prefix": "mdecimal", "description": "DecimalField (mdecimal) model field", "body": [ "${FIELDNAME} = models.DecimalField(${DESCRICAO}, max_digits=5, decimal_places=2)" ] }, "mduration": { "prefix": "mduration", "description": "DurationField (mduration) model field", "body": [ "${FIELDNAME} = models.DurationField(${DESCRICAO})" ] }, "memail": { "prefix": "memail", "description": "EmailField (memail) model field", "body": [ "${FIELDNAME} = models.EmailField(${DESCRICAO})" ] }, "mfile": { "prefix": "mfile", "description": "FileField (mfile) model field", "body": [ "${FIELDNAME} = models.FileField(${DESCRICAO})" ] }, "mfilepath": { "prefix": "mfilepath", "description": "FilePathField (mfilepath) model field", "body": [ "${FIELDNAME} = models.FilePathField(${DESCRICAO})" ] }, "mfloat": { "prefix": "mfloat", "description": " (mfloat) model field", "body": [ "${FIELDNAME} = models.FloatField(${DESCRICAO})" ] }, "mimg": { "prefix": "mimg", "description": "ImageField (mimg) model field", "body": [ "${FIELDNAME} = models.ImageField(${DESCRICAO}, upload_to='${SUBPASTA}')" ] }, "mint": { "prefix": "mint", "description": "IntegerField (mint) model field", "body": [ "${FIELDNAME} = models.IntegerField(${DESCRICAO})" ] }, "mip": { "prefix": "mip", "description": "IPAddressField (mip) model field", "body": [ "${FIELDNAME} = models.IPAddressField(${DESCRICAO})" ] }, "mnullbool": { "prefix": "mnullbool", "description": "NullBooleanField (mnullbool) model field", "body": [ "${FIELDNAME} = models.NullBooleanField(${DESCRICAO})" ] }, "mphone": { "prefix": "mphone", "description": "PhoneNumberField (mphone) model field", "body": [ "${FIELDNAME} = models.PhoneNumberField(${DESCRICAO})" ] }, "mposint": { "prefix": "mposint", "description": "PositiveIntegerField (mposint) model field", "body": [ "${FIELDNAME} = models.PositiveIntegerField(${DESCRICAO})" ] }, "mpossmallint": { "prefix": "mpossmallint", "description": "PositiveSmallIntegerField (mpossmallint) model field", "body": [ "${FIELDNAME} = models.PositiveSmallIntegerField(${DESCRICAO})" ] }, "mslug": { "prefix": "mslug", "description": "SlugField (mslug) model Field", "body": [ "${FIELDNAME} = models.SlugField(${DESCRICAO})" ] }, "msmallint": { "prefix": "msmallint", "description": "SmallIntegerField (msmallint) model field", "body": [ "${FIELDNAME} = models.SmallIntegerField(${DESCRICAO})" ] }, "mtext": { "prefix": "mtext", "description": "TextField (mtext) model field", "body": [ "${FIELDNAME} = models.TextField(${DESCRICAO})" ] }, "mtime": { "prefix": "mtime", "description": "TimeField (mtime) model field", "body": [ "${FIELDNAME} = models.TimeField(${DESCRICAO})" ] }, "murl": { "prefix": "murl", "description": "URLField (murl) model field", "body": [ "${FIELDNAME} = models.URLField(${DESCRICAO})" ] }, "musstate": { "prefix": "musstate", "description": "USStateField (musstate) model field", "body": [ "${FIELDNAME} = models.USStateField(${DESCRICAO})" ] }, "mxml": { "prefix": "mxml", "description": "XMLField (mxml) model field", "body": [ "${FIELDNAME} = models.XMLField(${DESCRICAO})" ] }, "fk": { "prefix": "mfo", "description": "ForeignKey (fk) model field", "body": [ "${FIELDNAME} = models.ForeignKey(${FKNAME}, on_delete=models.${PROTECT}, verbose_name='${DESCRICAO}', related_name='${RELACAO}')" ] }, "m2m": { "prefix": "m2m", "description": "ManyToManyField (m2m) model field", "body": [ "${FIELDNAME} = models.ManyToManyField(${FKNAME}, verbose_name='${DESCRICAO}', related_name='${RELACAO}')" ] }, "o2o": { "prefix": "o2o", "description": "OneToOneField (o2o) model field", "body": [ "${FIELDNAME} = models.OneToOneField(${DESCRICAO}, on_delete=models.${PROTECT})" ] }, "mserializer": { "prefix": "mserializer", "description": "ModelSerializer (mserializer) Rest Framework", "body": [ "class ${ModelName}Serializer(serializers.ModelSerializer):", "", "\tclass Meta:", "\t\tmodel = ${ModelName}", "\t\tfields = '__all__'" ] }, "mviewset": { "prefix": "mviewset", "description": "ModelViewSet (mviewset) Rest Framework", "body": [ "class ${ModelName}ViewSet(viewsets.ModelViewSet):", "", "\tqueryset = ${ModelName}.objects.all()", "\tserializer_class = ${ModelName}Serializer" ] }, "ronlymviewset": { "prefix": "ronlymviewset", "description": "ReadOnlyModelViewSet (ronlymviewset) Rest Framework", "body": [ "class ${ModelName}ViewSet(viewsets.ReadOnlyModelViewSet):", "", "\tqueryset = ${ModelName}.objects.all()", "\tserializer_class = ${ModelName}Serializer" ] }, "Model": { "prefix": "mmodel", "description": "models.Model (Model) Class Model of Django", "body": [ "class ${ModelName}(models.Model):", "", "\tdef __str__(self):", "\t\tpass", "", "\tclass Meta:", "\t\tdb_table = ''", "\t\tmanaged = True", "\t\tverbose_name = '${ModelName}'", "\t\tverbose_name_plural = '${ModelName}s'" ] }, "Meta": { "prefix": "mmeta", "description": "Meta (Meta) Meta Class of Model", "body": [ "class Meta:", "\tdb_table = ''", "\tmanaged = True", "\tverbose_name = '${ModelName}'", "\tverbose_name_plural = '${ModelName}s'" ] }, "adminRegister": { "prefix": "adr", "description": "Create admin site resgister for app", "body": [ "from .models import ${AppName}", "", "admin.site.register(${AppName})" ] }, "ondelete": { "prefix": "ond", "description": "on_delete option", "body": [ "on_delete=models.${PROTECT}" ] }, "null&blank": { "prefix": "nbl", "description": "null=True, blank=True option", "body": [ "null=True, blank=True" ] }, "Django CRUD Views": { "prefix": "dcv", "description": "Create CRUD views", "body": [ "from django.views.generic import ListView, CreateView, UpdateView, DeleteView", "from django.contrib.auth.mixins import LoginRequiredMixin", "from django.urls import reverse_lazy", "from .models import ${ClasseObjeto}", "", "class ${ClasseObjeto}List(LoginRequiredMixin, ListView):", "\tmodel = ${ClasseObjeto}", "", "class ${ClasseObjeto}Create(LoginRequiredMixin, CreateView):", "\tmodel = ${ClasseObjeto}", "\tform_class = None", "\tsuccess_url = reverse_lazy('${ClasseObjeto}_list')", "", "class ${ClasseObjeto}Update(LoginRequiredMixin, UpdateView):", "\tmodel = ${ClasseObjeto}", "\tform_class = None", "\tsuccess_url = reverse_lazy('${ClasseObjeto}_list')", "", "class ${ClasseObjeto}Delete(LoginRequiredMixin, DeleteView):", "\tmodel = ${ClasseObjeto}", "\tsuccess_url = reverse_lazy('${ClasseObjeto}_list')" ] }, "Django TemplateView": { "prefix": "dtv", "description": "Create a TemplateView", "body": [ "from django.views.generic import TemplateView", "from django.contrib.auth.mixins import LoginRequiredMixin", "", "class ${NomeClasse}(LoginRequiredMixin, TemplateView):", "\ttemplate_name = \"${arquivo}.html\"", "", "\tdef get_context_data(self, **kwargs):", "\t\tcontext = super().get_context_data(**kwargs)", "\t\tcontext['${var}'] = \"\"", "\t\treturn context" ] }, "Django ListView": { "prefix": "dclv", "description": "Create a ListView", "body": [ "class ${ClasseObjeto}Create(LoginRequiredMixin, ListView):", "\tmodel = ${ClasseObjeto}", "", "\tdef get_context_data(self, **kwargs):", "\t\tcontext = super().get_context_data(**kwargs)", "\t\tcontext['minha_variavel'] = 'Pode ser qualquer coisa'", "\t\treturn context" ] }, "Django CreateView": { "prefix": "dccv", "description": "Create a CreateView", "body": [ "class ${ClasseObjeto}Create(LoginRequiredMixin, CreateView):", "\tmodel = ${ClasseObjeto}", "\tform_class = None", "\tsuccess_url = reverse_lazy('${ClasseObjeto}_list')" ] }, "Django UpdateView": { "prefix": "dcuv", "description": "Create a UpdateView", "body": [ "class ${ClasseObjeto}Update(LoginRequiredMixin, UpdateView):", "\tmodel = ${ClasseObjeto}", "\tform_class = None", "\tsuccess_url = reverse_lazy('${ClasseObjeto}_list')" ] }, "Django DeleteView": { "prefix": "dcdv", "description": "Create a DeleteView", "body": [ "class ${ClasseObjeto}Delete(LoginRequiredMixin, DeleteView):", "\tmodel = ${ClasseObjeto}", "\tsuccess_url = reverse_lazy('${ClasseObjeto}_list')" ] }, "Django Settings Internationalization and Static": { "prefix": "dss", "description": "Create Internationalization and staticfolders settings", "body": [ "# Internationalization", "# https://docs.djangoproject.com/en/2.1/topics/i18n/", "", "LANGUAGE_CODE = 'pt-br'", "", "TIME_ZONE = 'America/Sao_Paulo'", "", "USE_I18N = True", "", "USE_L10N = True", "", "USE_TZ = True", "", "", "# Static files (CSS, JavaScript, Images)", "# https://docs.djangoproject.com/en/2.1/howto/static-files/", "", "STATIC_URL = '/static/'", "", "STATICFILES_DIRS = [", "\tos.path.join(BASE_DIR, \"staticfiles\"),", "]", "", "MEDIA_URL = '/media/'", "", "MEDIA_ROOT = os.path.join(BASE_DIR,'media')", "", "STATIC_ROOT = os.path.join(BASE_DIR,\"static/\")", "", "LOGIN_REDIRECT_URL = 'home'", "", "LOGOUT_REDIRECT_URL = 'login'" ] }, "Django Settings Template": { "prefix": "dst", "description": "Create template settings", "body": [ "TEMPLATES = [", "\t{", "\t\t'BACKEND': 'django.template.backends.django.DjangoTemplates',", "\t\t'DIRS': ['templates', os.path.join(BASE_DIR,'templates')],", "\t\t'APP_DIRS': True,", "\t\t'OPTIONS': {", "\t\t\t'context_processors': [", "\t\t\t\t'django.template.context_processors.debug',", "\t\t\t\t'django.template.context_processors.request',", "\t\t\t\t'django.contrib.auth.context_processors.auth',", "\t\t\t\t'django.contrib.messages.context_processors.messages',", "\t\t\t],", "\t\t},", "\t},", "]" ] }, "Django middleware": { "prefix": "middlweware", "description": "Create a middleware", "body": [ "def ${nome}_middleware(get_response):", "\tdef middleware(request):", "\t\tresponse = get_response(request)", "\t\treturn response", "\treturn middleware" ] }, "Django get_context_data": { "prefix": "dgetc", "description": "Create a get_context_data function", "body": [ "def get_context_data(self, **kwargs):", "\tcontext = super().get_context_data(**kwargs)", "\tcontext[\"${variavel}\"] = \"${valor}\"", "\treturn context" ] }, "Django post": { "prefix": "dpos", "description": "Create a post function", "body": [ "def post(self, request, *args, **kwargs):", "\treturn super().post(request, *args, **kwargs)" ] }, "Django get": { "prefix": "dget", "description": "Create a get function", "body": [ "def get(self, request, *args, **kwargs):", "\treturn super().get(request, *args, **kwargs)" ] }, "Django constraints": { "prefix": "dcons", "description": "Create a constraint for Meta Models", "body": [ "constraints = [", "\tmodels.UniqueConstraint(", "\t\tfields=[\"${cons1}\", \"${cons2}\"], name=\"${model}_${cons1}_${cons2}\",", "\t)", "]" ] }, "Pyhton def __str__": { "prefix": "defs", "description": "Create a __str__ function", "body": [ "def __str__(self):", "\treturn self.${NOME}" ] }, "Python encode": { "prefix": "enc", "description": "coding utf-8", "body": [ "# coding=utf-8" ] }, "Python Try/Except/Finally": { "prefix": "try", "description": "Command try/except/finally", "body": [ "try:", "\t${pass}", "except Exception as e:", "\tprint(\"{}\".format(e))", "finally:", "\tpass" ] } }