vim/snippets/django.snippets @ 215322e5a146

Update Vim plugins.
author Steve Losh <steve@stevelosh.com>
date Thu, 21 Jun 2012 09:55:44 -0400
parents 986fd59e3fae
children (none)
# Model Fields

# Note: Optional arguments are using defaults that match what Django will use
# as a default, e.g. with max_length fields.  Doing this as a form of self
# documentation and to make it easy to know whether you should override the
# default or not.

# Note: Optional arguments that are booleans will use the opposite since you
# can either not specify them, or override them, e.g. auto_now_add=False.

snippet auto
	${1:FIELDNAME} = models.AutoField()
snippet bool
	${1:FIELDNAME} = models.BooleanField(${2:default=True})
snippet char
	${1:FIELDNAME} = models.CharField(max_length=${2}${3:, blank=True})
snippet comma
	${1:FIELDNAME} = models.CommaSeparatedIntegerField(max_length=${2}${3:, blank=True})
snippet date
	${1:FIELDNAME} = models.DateField()
snippet datetime
	${1:FIELDNAME} = models.DateTimeField()
snippet decimal
	${1:FIELDNAME} = models.DecimalField(max_digits=${2}, decimal_places=${3})
snippet email
	${1:FIELDNAME} = models.EmailField(max_length=${2:75}${3:, blank=True})
snippet file
	${1:FIELDNAME} = models.FileField(upload_to=${2:path/for/upload}${3:, max_length=100})
snippet filepath
	${1:FIELDNAME} = models.FilePathField(path=${2:"/abs/path/to/dir"}${3:, max_length=100}${4:, match="*.ext"}${5:, recursive=True}${6:, blank=True, })
snippet float
	${1:FIELDNAME} = models.FloatField()
snippet image
	${1:FIELDNAME} = FileBrowseField(format='Image', max_length=200)
snippet djangoimage
	${1:FIELDNAME} = models.ImageField(upload_to=${2:path/for/upload}${3:, height_field=height, width_field=width}${4:, max_length=100})
snippet int
	${1:FIELDNAME} = models.IntegerField()
snippet ip
	${1:FIELDNAME} = models.IPAddressField()
snippet nullbool
	${1:FIELDNAME} = models.NullBooleanField()
snippet posint
	${1:FIELDNAME} = models.PositiveIntegerField()
snippet possmallint
	${1:FIELDNAME} = models.PositiveSmallIntegerField()
snippet slug
	${1:FIELDNAME} = models.SlugField(max_length=${2:50}${3:, blank=True})
snippet smallint
	${1:FIELDNAME} = models.SmallIntegerField()
snippet text
	${1:FIELDNAME} = models.TextField(${2:blank=True})
snippet time
	${1:FIELDNAME} = models.TimeField()
snippet url
	${1:FIELDNAME} = models.URLField(${2:verify_exists=False}${3:, max_length=200}${4:, blank=True})
snippet xml
	${1:FIELDNAME} = models.XMLField(schema_path=${2:None}${3:, blank=True})
# Relational Fields
snippet fk
	${1:FIELDNAME} = models.ForeignKey(${2:OtherModel})
snippet m2m
	${1:FIELDNAME} = models.ManyToManyField(${2:OtherModel})
snippet bl
	blank=True
snippet dc
	db_column='${1:colname}'
snippet dt
	db_table='${1:tablename}'
snippet o2o
	${1:FIELDNAME} = models.OneToOneField(${2:OtherModel}${3:, parent_link=True}${4:, related_name=''}${5:, limit_choices_to=}${6:, to_field=''})

# Code Skeletons

snippet form
	class ${1:FormName}(forms.Form):
		"""${2:docstring}"""
		${3}

snippet manager
	class ${1:ModelName}Manager(models.Manager):
		def get_query_set(self):
			return super($1Manager, self).get_query_set()
		${3}

snippet model
	class ${1:ModelName}(${2:models.Model}):
		${4}

		class Meta:
			ordering = ('${3:-created}',)

		def __unicode__(self):
			return u'%s' % ''

snippet modeladmin
	class ${1:ModelName}Admin(admin.ModelAdmin):
		${2}
	
	admin.site.register($1, $1Admin)

snippet r2r
	return render_to_response('${1:template.html}', {
			${2}
		}${3:, context_instance=RequestContext(request)}
	)

snippet tabularinline
	class ${1:ModelName}Inline(admin.TabularInline):
		model = $1
		extra = ${2:3}

snippet stackedinline
	class ${1:ModelName}Inline(admin.StackedInline):
		model = $1
		extra = ${2:3}

# Ugly crap.

snippet reverse
	reverse('${1:view-name}'${2:, args=[]}${3:, kwargs=None})${4}
snippet view
	@render_to('${1}')
	def ${2:view_name}(request${3:, ...}):${4}
		return {}
snippet defu
	def __unicode__(self):
		return u'${1}' % (${2})