2012-08-16 23:41:25 -04:00
|
|
|
# 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
|
2013-11-16 14:45:48 -05:00
|
|
|
${1:FIELDNAME} = models.AutoField(${0})
|
2012-08-16 23:41:25 -04:00
|
|
|
snippet bool
|
2013-11-16 14:45:48 -05:00
|
|
|
${1:FIELDNAME} = models.BooleanField(${0:default=True})
|
2012-08-16 23:41:25 -04:00
|
|
|
snippet char
|
2013-11-16 14:45:48 -05:00
|
|
|
${1:FIELDNAME} = models.CharField(max_length=${2}${0:, blank=True})
|
2012-08-16 23:41:25 -04:00
|
|
|
snippet comma
|
2013-11-16 14:45:48 -05:00
|
|
|
${1:FIELDNAME} = models.CommaSeparatedIntegerField(max_length=${2}${0:, blank=True})
|
2012-08-16 23:41:25 -04:00
|
|
|
snippet date
|
2013-11-16 14:45:48 -05:00
|
|
|
${1:FIELDNAME} = models.DateField(${2:auto_now_add=True, auto_now=True}${0:, blank=True, null=True})
|
2012-08-16 23:41:25 -04:00
|
|
|
snippet datetime
|
2013-11-16 14:45:48 -05:00
|
|
|
${1:FIELDNAME} = models.DateTimeField(${2:auto_now_add=True, auto_now=True}${0:, blank=True, null=True})
|
2012-08-16 23:41:25 -04:00
|
|
|
snippet decimal
|
2013-11-16 14:45:48 -05:00
|
|
|
${1:FIELDNAME} = models.DecimalField(max_digits=${2}, decimal_places=${0})
|
2012-08-16 23:41:25 -04:00
|
|
|
snippet email
|
2013-11-16 14:45:48 -05:00
|
|
|
${1:FIELDNAME} = models.EmailField(max_length=${2:75}${0:, blank=True})
|
2012-08-16 23:41:25 -04:00
|
|
|
snippet file
|
2013-11-16 14:45:48 -05:00
|
|
|
${1:FIELDNAME} = models.FileField(upload_to=${2:path/for/upload}${0:, max_length=100})
|
2012-08-16 23:41:25 -04:00
|
|
|
snippet filepath
|
2013-11-16 14:45:48 -05:00
|
|
|
${1:FIELDNAME} = models.FilePathField(path=${2:"/abs/path/to/dir"}${3:, max_length=100}${4:, match="*.ext"}${5:, recursive=True}${0:, blank=True, })
|
2012-08-16 23:41:25 -04:00
|
|
|
snippet float
|
2013-11-16 14:45:48 -05:00
|
|
|
${1:FIELDNAME} = models.FloatField(${0})
|
2012-08-16 23:41:25 -04:00
|
|
|
snippet image
|
2013-11-16 14:45:48 -05:00
|
|
|
${1:FIELDNAME} = models.ImageField(upload_to=${2:path/for/upload}${3:, height_field=height, width_field=width}${0:, max_length=100})
|
2012-08-16 23:41:25 -04:00
|
|
|
snippet int
|
2013-11-16 14:45:48 -05:00
|
|
|
${1:FIELDNAME} = models.IntegerField(${0})
|
2012-08-16 23:41:25 -04:00
|
|
|
snippet ip
|
2013-11-16 14:45:48 -05:00
|
|
|
${1:FIELDNAME} = models.IPAddressField(${0})
|
2012-08-16 23:41:25 -04:00
|
|
|
snippet nullbool
|
2013-11-16 14:45:48 -05:00
|
|
|
${1:FIELDNAME} = models.NullBooleanField(${0})
|
2012-08-16 23:41:25 -04:00
|
|
|
snippet posint
|
2013-11-16 14:45:48 -05:00
|
|
|
${1:FIELDNAME} = models.PositiveIntegerField(${0})
|
2012-08-16 23:41:25 -04:00
|
|
|
snippet possmallint
|
2013-11-16 14:45:48 -05:00
|
|
|
${1:FIELDNAME} = models.PositiveSmallIntegerField(${0})
|
2012-08-16 23:41:25 -04:00
|
|
|
snippet slug
|
2013-11-16 14:45:48 -05:00
|
|
|
${1:FIELDNAME} = models.SlugField(max_length=${2:50}${0:, blank=True})
|
2012-08-16 23:41:25 -04:00
|
|
|
snippet smallint
|
2013-11-16 14:45:48 -05:00
|
|
|
${1:FIELDNAME} = models.SmallIntegerField(${0})
|
2012-08-16 23:41:25 -04:00
|
|
|
snippet text
|
2013-11-16 14:45:48 -05:00
|
|
|
${1:FIELDNAME} = models.TextField(${0:blank=True})
|
2012-08-16 23:41:25 -04:00
|
|
|
snippet time
|
2013-11-16 14:45:48 -05:00
|
|
|
${1:FIELDNAME} = models.TimeField(${2:auto_now_add=True, auto_now=True}${0:, blank=True, null=True})
|
2012-08-16 23:41:25 -04:00
|
|
|
snippet url
|
2013-11-16 14:45:48 -05:00
|
|
|
${1:FIELDNAME} = models.URLField(${2:verify_exists=False}${3:, max_length=200}${0:, blank=True})
|
2012-08-16 23:41:25 -04:00
|
|
|
snippet xml
|
2013-11-16 14:45:48 -05:00
|
|
|
${1:FIELDNAME} = models.XMLField(schema_path=${2:None}${0:, blank=True})
|
2012-08-16 23:41:25 -04:00
|
|
|
# Relational Fields
|
|
|
|
snippet fk
|
2013-11-16 14:45:48 -05:00
|
|
|
${1:FIELDNAME} = models.ForeignKey(${2:OtherModel}${3:, related_name=''}${4:, limit_choices_to=}${0:, to_field=''})
|
2012-08-16 23:41:25 -04:00
|
|
|
snippet m2m
|
2013-11-16 14:45:48 -05:00
|
|
|
${1:FIELDNAME} = models.ManyToManyField(${2:OtherModel}${3:, related_name=''}${4:, limit_choices_to=}${5:, symmetrical=False}${6:, through=''}${0:, db_table=''})
|
2012-08-16 23:41:25 -04:00
|
|
|
snippet o2o
|
2013-11-16 14:45:48 -05:00
|
|
|
${1:FIELDNAME} = models.OneToOneField(${2:OtherModel}${3:, parent_link=True}${4:, related_name=''}${5:, limit_choices_to=}${0:, to_field=''})
|
2012-08-16 23:41:25 -04:00
|
|
|
|
|
|
|
# Code Skeletons
|
|
|
|
|
|
|
|
snippet form
|
|
|
|
class ${1:FormName}(forms.Form):
|
|
|
|
"""${2:docstring}"""
|
2013-11-16 14:45:48 -05:00
|
|
|
${0}
|
2012-08-16 23:41:25 -04:00
|
|
|
|
|
|
|
snippet model
|
|
|
|
class ${1:ModelName}(models.Model):
|
|
|
|
"""${2:docstring}"""
|
|
|
|
${3}
|
2013-07-17 19:06:05 -04:00
|
|
|
|
2012-08-16 23:41:25 -04:00
|
|
|
class Meta:
|
|
|
|
${4}
|
2013-07-17 19:06:05 -04:00
|
|
|
|
2012-08-16 23:41:25 -04:00
|
|
|
def __unicode__(self):
|
|
|
|
${5}
|
2013-07-17 19:06:05 -04:00
|
|
|
|
2012-08-16 23:41:25 -04:00
|
|
|
def save(self, force_insert=False, force_update=False):
|
|
|
|
${6}
|
2013-07-17 19:06:05 -04:00
|
|
|
|
2012-08-16 23:41:25 -04:00
|
|
|
@models.permalink
|
|
|
|
def get_absolute_url(self):
|
2013-11-16 14:45:48 -05:00
|
|
|
return ('${7:view_or_url_name}' ${0})
|
2012-08-16 23:41:25 -04:00
|
|
|
|
|
|
|
snippet modeladmin
|
|
|
|
class ${1:ModelName}Admin(admin.ModelAdmin):
|
2013-11-16 14:45:48 -05:00
|
|
|
${0}
|
2013-07-17 19:06:05 -04:00
|
|
|
|
2012-08-16 23:41:25 -04:00
|
|
|
admin.site.register($1, $1Admin)
|
2013-07-17 19:06:05 -04:00
|
|
|
|
2012-08-16 23:41:25 -04:00
|
|
|
snippet tabularinline
|
2013-11-16 14:45:48 -05:00
|
|
|
class ${0:ModelName}Inline(admin.TabularInline):
|
2012-08-16 23:41:25 -04:00
|
|
|
model = $1
|
|
|
|
|
|
|
|
snippet stackedinline
|
2013-11-16 14:45:48 -05:00
|
|
|
class ${0:ModelName}Inline(admin.StackedInline):
|
2012-08-16 23:41:25 -04:00
|
|
|
model = $1
|
|
|
|
|
|
|
|
snippet r2r
|
|
|
|
return render_to_response('${1:template.html}', {
|
|
|
|
${2}
|
2013-11-16 14:45:48 -05:00
|
|
|
}${0:, context_instance=RequestContext(request)}
|
2012-08-16 23:41:25 -04:00
|
|
|
)
|