Skip to content

Commit 628b45b

Browse files
committed
Make writing PATCH method easier
1 parent 18669a6 commit 628b45b

File tree

4 files changed

+16
-4
lines changed

4 files changed

+16
-4
lines changed

freenit/api/__init__.py

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,2 +1,3 @@
1-
from .router import api
21
import freenit.api.user
2+
3+
from .router import api

freenit/models/base.py

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,11 @@
1+
import ormar
2+
3+
4+
class BaseModel(ormar.Model):
5+
async def patch(self, fields):
6+
result = {}
7+
data = fields.dict()
8+
for k in data:
9+
if data[k] is not None:
10+
result[k] = data[k]
11+
return await self.update(**result)

freenit/models/mixins.py renamed to freenit/models/metaclass.py

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,9 +1,9 @@
11
from typing import Optional
22

3-
import pydantic
3+
import ormar
44

55

6-
class AllOptional(pydantic.main.ModelMetaclass):
6+
class AllOptional(ormar.models.metaclass.ModelMetaclass):
77
def __new__(cls, name, bases, namespaces, **kwargs):
88
annotations = namespaces.get("__annotations__", {})
99
for base in bases:

freenit/version.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1 +1 @@
1-
version = "0.2.8"
1+
version = "0.2.9"

0 commit comments

Comments
 (0)