Search code examples
djangodjango-modelsslug

Periods in Django's SlugField


Question

  • Why can data loaded via the initial_data.yaml fixture populate a SlugField with a slug containing a period and not generate an error?

Code

Here's an excerpt of the model:

class Project(models.Model):
    slug_code = models.SlugField(max_length=15)

Here's the applicable initial_data.yaml excerpt:

- model: myapp.project
  pk: 1
  fields:
    slug_code: TIDE.024

The yaml fixture initial_data.yaml is installed without any errors. When I log into the Admin and look at the Project model, I can see that the SlugField slug_code contains TIDE.024, but when I change the slug_code field to say TIDE.025 the Admin generates the following error:

Enter a valid 'slug' consisting of letters, numbers, underscores or hyphens.

Configuration

  • Django v1.1.1
  • PyYAML v3.09

Solution

  • The value in the SlugField is only checked in forms, not in the database.