-
-
Notifications
You must be signed in to change notification settings - Fork 3.6k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Version: use field validator instead of custom field for slug (#11957)
Instead of having a custom field with some extra complexity, we can achieve the same result by using a more standard django pattern, populating the field if isn't defined and using a validator. This will help to re-use this code in #11930.
- Loading branch information
Showing
6 changed files
with
141 additions
and
180 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,33 @@ | ||
# Generated by Django 4.2.17 on 2025-01-27 18:32 | ||
|
||
import django.core.validators | ||
from django.db import migrations, models | ||
from django_safemigrate import Safe | ||
|
||
|
||
class Migration(migrations.Migration): | ||
|
||
safe = Safe.after_deploy | ||
|
||
dependencies = [ | ||
("builds", "0059_add_version_date_index"), | ||
] | ||
|
||
operations = [ | ||
migrations.AlterField( | ||
model_name="version", | ||
name="slug", | ||
field=models.CharField( | ||
db_index=True, | ||
help_text="A unique identifier used in the URL and links for this version. It can contain lowercase letters, numbers, dots, dashes or underscores. It must start with a lowercase letter or a number.", | ||
max_length=255, | ||
validators=[ | ||
django.core.validators.RegexValidator( | ||
message="Enter a valid slug consisting of lowercase letters, numbers, dots, dashes or underscores. It must start with a letter or a number.", | ||
regex="^(?:[a-z0-9a-z][-._a-z0-9a-z]*?)$", | ||
) | ||
], | ||
verbose_name="Slug", | ||
), | ||
), | ||
] |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.