Skip to content

Commit

Permalink
Merge pull request #1185 from jlost/smallautofield
Browse files Browse the repository at this point in the history
Add ORM support for SmallAutoField
  • Loading branch information
vitalik authored Jun 27, 2024
2 parents 2b69b16 + d377067 commit db00649
Show file tree
Hide file tree
Showing 2 changed files with 17 additions and 13 deletions.
1 change: 1 addition & 0 deletions ninja/orm/fields.py
Original file line number Diff line number Diff line change
Expand Up @@ -65,6 +65,7 @@ def validate(cls, value: Any, _: Any) -> Any:
"PositiveIntegerField": int,
"PositiveSmallIntegerField": int,
"SlugField": str,
"SmallAutoField": int,
"SmallIntegerField": int,
"TextField": str,
"TimeField": datetime.time,
Expand Down
29 changes: 16 additions & 13 deletions tests/test_orm_schemas.py
Original file line number Diff line number Diff line change
Expand Up @@ -191,24 +191,27 @@ class Meta:
}


def test_bigautofield():
class ModelBigAuto(models.Model):
bigautofiled = models.BigAutoField(primary_key=True)
@pytest.mark.parametrize(
"field",
[
models.BigAutoField,
models.SmallAutoField,
]
)
def test_altautofield(field: type):
class ModelAltAuto(models.Model):
altautofield = field(primary_key=True)

class Meta:
app_label = "tests"

SchemaCls = create_schema(ModelBigAuto)
SchemaCls = create_schema(ModelAltAuto)
# print(SchemaCls.json_schema())
assert SchemaCls.json_schema() == {
"type": "object",
"properties": {
"bigautofiled": {
"anyOf": [{"type": "integer"}, {"type": "null"}],
"title": "Bigautofiled",
}
},
"title": "ModelBigAuto",
assert SchemaCls.json_schema()["properties"] == {
"altautofield": {
"anyOf": [{"type": "integer"}, {"type": "null"}],
"title": "Altautofield",
}
}


Expand Down

0 comments on commit db00649

Please sign in to comment.