Skip to content
This repository was archived by the owner on Aug 19, 2025. It is now read-only.

Commit 3e1205f

Browse files
authored
Add URL field (#128)
1 parent 05432d0 commit 3e1205f

File tree

4 files changed

+20
-1
lines changed

4 files changed

+20
-1
lines changed

docs/declaring_models.md

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -68,6 +68,7 @@ See `TypeSystem` for [type-specific validation keyword arguments][typesystem-fie
6868
* `orm.String(max_length)`
6969
* `orm.Text()`
7070
* `orm.Time()`
71+
* `orm.URL(max_length)`
7172
* `orm.UUID()`
7273
* `orm.JSON()`
7374

orm/__init__.py

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,7 @@
22
from orm.exceptions import MultipleMatches, NoMatch
33
from orm.fields import (
44
JSON,
5+
URL,
56
UUID,
67
BigInteger,
78
Boolean,
@@ -44,6 +45,7 @@
4445
"String",
4546
"Text",
4647
"Time",
48+
"URL",
4749
"UUID",
4850
"Model",
4951
"ModelRegistry",

orm/fields.py

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -250,3 +250,11 @@ def get_validator(self, **kwargs) -> typesystem.Field:
250250

251251
def get_column_type(self):
252252
return GenericIP()
253+
254+
255+
class URL(String):
256+
def get_validator(self, **kwargs) -> typesystem.Field:
257+
return typesystem.URL(**kwargs)
258+
259+
def get_column_type(self):
260+
return sqlalchemy.String(length=self.validator.max_length)

tests/test_columns.py

Lines changed: 9 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -49,6 +49,7 @@ class User(orm.Model):
4949
"name": orm.String(allow_null=True, max_length=16),
5050
"email": orm.Email(allow_null=True, max_length=256),
5151
"ipaddress": orm.IPAddress(allow_null=True),
52+
"url": orm.URL(allow_null=True, max_length=2048),
5253
}
5354

5455

@@ -101,8 +102,15 @@ async def test_model_crud():
101102
user = await User.objects.get()
102103
assert user.email is None
103104
assert user.ipaddress is None
105+
assert user.url is None
104106

105-
await user.update(ipaddress="192.168.1.1", name="Chris", email="[email protected]")
107+
await user.update(
108+
ipaddress="192.168.1.1",
109+
name="Chris",
110+
111+
url="https://encode.io",
112+
)
106113

107114
user = await User.objects.get()
108115
assert isinstance(user.ipaddress, (ipaddress.IPv4Address, ipaddress.IPv6Address))
116+
assert user.url == "https://encode.io"

0 commit comments

Comments
 (0)