-
Notifications
You must be signed in to change notification settings - Fork 213
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Add text-based URL field, change columns to text
- Loading branch information
1 parent
0c39a99
commit 9f69c08
Showing
3 changed files
with
38 additions
and
21 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,21 @@ | ||
from django import forms | ||
from django.core import validators | ||
from django.db import models | ||
from django.utils.translation import gettext_lazy as _ | ||
|
||
|
||
class URLTextField(models.TextField): | ||
"""URL field which uses the underlying Postgres TEXT column type.""" | ||
|
||
default_validators = [validators.URLValidator()] | ||
description = _("URL") | ||
|
||
def formfield(self, **kwargs): | ||
# As with CharField, this will cause URL validation to be performed | ||
# twice. | ||
return super().formfield( | ||
**{ | ||
"form_class": forms.URLField, | ||
**kwargs, | ||
} | ||
) |
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