Last modified: Jan 10, 2023 By Alexander Williams
Django models.SlugField Examples
Example 1
class Person(models.Model):
name = models.CharField(max_length=200)
slug = models.SlugField(max_length=100, unique=True)
priority = models.PositiveSmallIntegerField(default=1)
Example 2
class Genre(models.Model):
genre= models.CharField(max_length=255)
genre_slug= models.SlugField()
def __unicode__(self):
return self.genre
Example 3
class Zipcode(models.Model):
zipcode= models.CharField(max_length=255)
zipcode_slug= models.SlugField()
def __unicode__(self):
return self.zipcode
Example 4
class Location(models.Model):
title = models.CharField(max_length=225)
title_slug= models.SlugField()
address = models.CharField(max_length=225)
city = models.ForeignKey(City)
state = models.ForeignKey(State)
zipcode = models.ForeignKey(Zipcode)
description = models.TextField()
def __unicode__(self):
return self.location
Example 5
class Categories(models.Model):
slug = models.SlugField(max_length=100, unique=True)
name = models.CharField(max_length=200)
priority = models.PositiveSmallIntegerField(default=1)
Example 6
class Tag(models.Model):
slug = models.SlugField(max_length=100, unique=True)
name = models.CharField(max_length=200)
priority = models.PositiveSmallIntegerField(default=1)