Skip to content

Commit a651b89

Browse files
committed
Fix Django schema deprecation
1 parent a808e68 commit a651b89

File tree

1 file changed

+8
-0
lines changed

1 file changed

+8
-0
lines changed

devel/forms.py

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -11,6 +11,7 @@
1111
from django.template import loader
1212

1313
from .models import UserProfile
14+
from django.db.models import URLField
1415

1516

1617
class ProfileForm(forms.Form):
@@ -31,6 +32,11 @@ def clean(self):
3132
raise forms.ValidationError('Passwords do not match.')
3233
return self.cleaned_data
3334

35+
def _urlfields_assume_https(db_field, **kwargs):
36+
if isinstance(db_field, URLField):
37+
kwargs["assume_scheme"] = "https"
38+
return db_field.formfield(**kwargs)
39+
3440

3541
class UserProfileForm(forms.ModelForm):
3642
def clean_pgp_key(self):
@@ -46,6 +52,7 @@ class Meta:
4652
widgets = {
4753
'yob': NumberInput(attrs={'min': 1950, 'max': date.today().year - 10}),
4854
}
55+
formfield_callback = _urlfields_assume_https
4956

5057

5158
class NewUserForm(forms.ModelForm):
@@ -58,6 +65,7 @@ class NewUserForm(forms.ModelForm):
5865
class Meta:
5966
model = UserProfile
6067
exclude = ('picture', 'user')
68+
formfield_callback = _urlfields_assume_https
6169

6270
def __init__(self, *args, **kwargs):
6371
super(NewUserForm, self).__init__(*args, **kwargs)

0 commit comments

Comments
 (0)