vimrc/sources_non_forked/vim-snippets/UltiSnips/django.snippets
2017-09-02 12:43:18 +02:00

361 lines
7.6 KiB
Text
Raw Blame History

This file contains invisible Unicode characters

This file contains invisible Unicode characters that are indistinguishable to humans but may be processed differently by a computer. If you think that this is intentional, you can safely ignore this warning. Use the Escape button to reveal them.

priority -50
# This files will define django snippets from sublime text djaneiro
# FORMS SNIPPETS
snippet form "Form" b
class ${1:FORMNAME}(forms.Form):
${2:# TODO: Define form fields here}
endsnippet
snippet modelform "ModelForm" b
class ${1:MODELNAME}Form(forms.ModelForm):
class Meta:
model = $1
endsnippet
snippet fbool "BooleanField" b
${1:FIELDNAME} = forms.BooleanField($2)
endsnippet
snippet fchar "CharField" b
${1:FIELDNAME} = forms.CharField($2)
endsnippet
snippet fchoice "ChoiceField" b
${1:FIELDNAME} = forms.ChoiceField($2)
endsnippet
snippet fcombo "ComboField" b
${1:FIELDNAME} = forms.ComboField($2)
endsnippet
snippet fdate "DateField" b
${1:FIELDNAME} = forms.DateField($2)
endsnippet
snippet fdatetime "DateTimeField" b
${1:FIELDNAME} = forms.DateTimeField($2)
endsnippet
snippet fdecimal "DecimalField" b
${1:FIELDNAME} = forms.DecimalField($2)
endsnippet
snippet fmail "EmailField" b
${1:FIELDNAME} = forms.EmailField($2)
endsnippet
snippet ffile "FileField" b
${1:FIELDNAME} = forms.FileField($2)
endsnippet
snippet ffilepath "FilePathField" b
${1:FIELDNAME} = forms.FilePathField($2)
endsnippet
snippet ffloat "FloatField" b
${1:FIELDNAME} = forms.FloatField($2)
endsnippet
snippet fip "IPAddressField" b
${1:FIELDNAME} = forms.IPAddressField($2)
endsnippet
snippet fimg "ImageField" b
${1:FIELDNAME} = forms.ImageField($2)
endsnippet
snippet fint "IntegerField" b
${1:FIELDNAME} = forms.IntegerField($2)
endsnippet
snippet fmochoice "ModelChoiceField" b
${1:FIELDNAME} = forms.ModelChoiceField($2)
endsnippet
snippet fmomuchoice "ModelMultipleChoiceField" b
${1:FIELDNAME} = forms.ModelMultipleChoiceField($2)
endsnippet
snippet fmuval "MultiValueField" b
${1:FIELDNAME} = forms.MultiValueField($2)
endsnippet
snippet fmuchoice "MultipleChoiceField" b
${1:FIELDNAME} = forms.MultipleChoiceField($2)
endsnippet
snippet fnullbool "NullBooleanField" b
${1:FIELDNAME} = forms.NullBooleanField($2)
endsnippet
snippet freg "RegexField" b
${1:FIELDNAME} = forms.RegexField($2)
endsnippet
snippet fslug "SlugField" b
${1:FIELDNAME} = forms.SlugField($2)
endsnippet
snippet fsdatetime "SplitDateTimeField" b
${1:FIELDNAME} = forms.SplitDateTimeField($2)
endsnippet
snippet ftime "TimeField" b
${1:FIELDNAME} = forms.TimeField($2)
endsnippet
snippet ftchoice "TypedChoiceField" b
${1:FIELDNAME} = forms.TypedChoiceField($2)
endsnippet
snippet ftmuchoice "TypedMultipleChoiceField" b
${1:FIELDNAME} = forms.TypedMultipleChoiceField($2)
endsnippet
snippet furl "URLField" b
${1:FIELDNAME} = forms.URLField($2)
endsnippet
# MODELS SNIPPETS
snippet model "Model" b
class ${1:MODELNAME}(models.Model):
$0
class Meta:
verbose_name = "$1"
verbose_name_plural = "$1s"
def __str__(self):
return super($1, self).__str__()
endsnippet
snippet modelfull "Model" b
class ${1:MODELNAME}(models.Model):
${2:# TODO: Define fields here}
class Meta:
verbose_name = "$1"
verbose_name_plural = "$1s"
def __str__(self):
return super($1, self).__str__()
def save(self):
return super($1, self).save()
@models.permalink
def get_absolute_url(self):
return ('')
${3:# TODO: Define custom methods here}
endsnippet
snippet mauto "AutoField" b
${1:FIELDNAME} = models.AutoField($2)
endsnippet
snippet mbigint "BigIntegerField" b
${1:FIELDNAME} = models.BigIntegerField($2)
endsnippet
snippet mbool "BooleanField" b
${1:FIELDNAME} = models.BooleanField($2)
endsnippet
snippet mchar "CharField" b
${1:FIELDNAME} = models.CharField($2, max_length=${3:50})
endsnippet
snippet mcoseint "CommaSeparatedIntegerField" b
${1:FIELDNAME} = models.CommaSeparatedIntegerField($2)
endsnippet
snippet mdate "DateField" b
${1:FIELDNAME} = models.DateField($2)
endsnippet
snippet mdatetime "DateTimeField" b
${1:FIELDNAME} = models.DateTimeField($2)
endsnippet
snippet mdecimal "DecimalField" b
${1:FIELDNAME} = models.DecimalField(max_digits=${2:10}, decimal_places=${3:2})
endsnippet
snippet memail "EmailField" b
${1:FIELDNAME} = models.EmailField($2)
endsnippet
snippet mfile "FileField" b
${1:FIELDNAME} = models.FileField($2)
endsnippet
snippet mfilepath "FilePathField" b
${1:FIELDNAME} = models.FilePathField($2)
endsnippet
snippet mfloat "FloatField" b
${1:FIELDNAME} = models.FloatField($2)
endsnippet
snippet fk "ForeignKey" b
${1:FIELDNAME} = models.ForeignKey($2)
endsnippet
snippet mip "IPAddressField" b
${1:FIELDNAME} = models.IPAddressField($2)
endsnippet
snippet mimg "ImageField" b
${1:FIELDNAME} = models.ImageField($2)
endsnippet
snippet mint "IntegerField" b
${1:FIELDNAME} = models.IntegerField($2)
endsnippet
snippet m2m "ManyToManyField" b
${1:FIELDNAME} = models.ManyToManyField($2)
endsnippet
snippet mnullbool "NullBooleanField" b
${1:FIELDNAME} = models.NullBooleanField($2)
endsnippet
snippet o2o "OneToOneField" b
${1:FIELDNAME} = models.OneToOneField($2)
endsnippet
snippet mphone "PhoneNumberField" b
${1:FIELDNAME} = models.PhoneNumberField($2)
endsnippet
snippet mposint "PositiveIntegerField" b
${1:FIELDNAME} = models.PositiveIntegerField($2)
endsnippet
snippet mpossmallint "PositiveSmallIntegerField" b
${1:FIELDNAME} = models.PositiveSmallIntegerField($2)
endsnippet
snippet mslug "SlugField" b
${1:FIELDNAME} = models.SlugField($2)
endsnippet
snippet msmallint "SmallIntegerField" b
${1:FIELDNAME} = models.SmallIntegerField($2)
endsnippet
snippet mtext "TextField" b
${1:FIELDNAME} = models.TextField($2)
endsnippet
snippet mtime "TimeField" b
${1:FIELDNAME} = models.TimeField($2)
endsnippet
snippet murl "URLField" b
${1:FIELDNAME} = models.URLField($2)
endsnippet
snippet musstate "USStateField" b
${1:FIELDNAME} = models.USStateField($2)
endsnippet
snippet mxml "XMLField" b
${1:FIELDNAME} = models.XMLField($2)
endsnippet
# VIEWS SNIPPETS
snippet adminview "Model Admin View" b
class $1Admin(admin.ModelAdmin):
'''
Admin View for $1
'''
list_display = ('$2',)
list_filter = ('$3',)
inlines = [
$4Inline,
]
raw_id_fields = ('$5',)
readonly_fields = ('$6',)
search_fields = ['$7']
admin.site.register($1, $1Admin)
endsnippet
snippet createview "Generic Create View" b
class ${1:MODEL_NAME}CreateView(CreateView):
model = $1
template_name = "${2:TEMPLATE_NAME}"
endsnippet
snippet deleteview "Generic Delete View" b
class ${1:MODEL_NAME}DeleteView(DeleteView):
model = $1
template_name = "${2:TEMPLATE_NAME}"
endsnippet
snippet detailview "Generic Detail View" b
class ${1:MODEL_NAME}DetailView(DetailView):
model = $1
template_name = "${2:TEMPLATE_NAME}"
endsnippet
snippet listview "Generic List View" b
class ${1:MODEL_NAME}ListView(ListView):
model = $1
template_name = "${2:TEMPLATE_NAME}"
endsnippet
snippet stackedinline "Stacked Inline" b
class $1Inline(admin.StackedInline):
'''
Stacked Inline View for $1
'''
model = ${2:$1}
min_num = ${3:3}
max_num = ${4:20}
extra = ${5:1}
raw_id_fields = ($6,)
endsnippet
snippet tabularinline "Tabular Inline" b
class $1Inline(admin.TabularInline):
'''
Tabular Inline View for $1
'''
model = ${2:$1}
min_num = ${3:3}
max_num = ${4:20}
extra = ${5:1}
raw_id_fields = ($6,)
endsnippet
snippet templateview "Generic Template View" b
class ${1:CLASS_NAME}(TemplateView):
template_name = "${2:TEMPLATE_NAME}"
endsnippet
snippet updateview "Generic Update View" b
class ${1:MODEL_NAME}UpdateView(UpdateView):
model = $1
template_name = "${2:TEMPLATE_NAME}"
endsnippet
snippet dispatch "Dispatch View method" b
def dispatch(self, request, *args, **kwargs):
return super(${1:CLASS_NAME}, self).dispatch(request, *args, **kwargs)
endsnippet
snippet context "get_context_data view method" b
def get_context_data(self, **kwargs):
kwargs['extra_context'] = ${1:'New Value'}
return super(${2:CLASS_NAME}, self).get_context_data(**kwargs)
endsnippet