﻿id	summary	reporter	owner	description	type	status	component	version	severity	resolution	keywords	cc	stage	has_patch	needs_docs	needs_tests	needs_better_patch	easy	ui_ux
36923	URLField.to_python() mangles mailto: URLs	waveywhite	Natalia Bidart	"Having derived from django.forms.URLField and django.models.URLField to set up a form that can handle mailto URLs, I'm finding that the URL gets mangled. Entering ""mailto:test@example.com"" results in ""mailto://test@example.com"".

This was encountered while creating models for a Wagtail site. Wagtail uses Django's models and form fields within its framework.

My modified URLFields:

{{{
from django import forms
from django.db import models

class ContactUrlFormField(forms.URLField):
    default_validators = [
        validators.URLValidator(schemes=['http', 'https', 'mailto', 'tel'])
    ]

class ContactUrlField(models.URLField):
    default_validators = [
        validators.URLValidator(schemes=['http', 'https', 'mailto', 'tel'])
    ]
    
    def formfield(self, **kwargs):
        return super().formfield(
            **{
                ""form_class"": ContactUrlFormField,
                **kwargs,
            }
        )
}}}

NB. It would be great to have a way of defining which URL schemes are allowed as an option in the model field and then have it picked up by the form field automatically.
"	Bug	closed	Forms	5.2	Normal	fixed	mailto urlfield	waveywhite	Ready for checkin	1	0	0	0	0	0
