add callable excecution and test for default value, update readme with exclude, bump version

This commit is contained in:
collerek
2020-09-17 18:10:10 +02:00
parent 1a4be03131
commit d0161a81af
5 changed files with 11 additions and 2 deletions

BIN
.coverage

Binary file not shown.

View File

@ -82,6 +82,9 @@ notes = await Note.objects.filter(completed=True).all()
# exact, iexact, contains, icontains, lt, lte, gt, gte, in
notes = await Note.objects.filter(text__icontains="mum").all()
# exclude - from ormar >= 0.3.1
notes = await Note.objects.exclude(text__icontains="mum").all()
# .get()
note = await Note.objects.get(id=1)

View File

@ -26,7 +26,7 @@ class UndefinedType: # pragma no cover
Undefined = UndefinedType()
__version__ = "0.3.0"
__version__ = "0.3.1"
__all__ = [
"Integer",
"BigInteger",

View File

@ -41,7 +41,10 @@ class BaseField:
@classmethod
def get_default(cls) -> Any:
if cls.has_default():
return cls.default if cls.default is not None else cls.server_default
default = cls.default if cls.default is not None else cls.server_default
if callable(default):
default = default()
return default
@classmethod
def has_default(cls) -> bool:

View File

@ -1,4 +1,5 @@
import asyncio
from datetime import datetime
import databases
import pydantic
@ -43,6 +44,7 @@ class Product(ormar.Model):
name: ormar.String(max_length=100)
rating: ormar.Integer(minimum=1, maximum=5)
in_stock: ormar.Boolean(default=False)
last_delivery: ormar.Date(default=datetime.now)
@pytest.fixture(scope="module")
@ -158,6 +160,7 @@ async def test_model_filter():
assert product.pk is not None
assert product.name == "T-Shirt"
assert product.rating == 5
assert product.last_delivery == datetime.now().date()
products = await Product.objects.all(rating__gte=2, in_stock=True)
assert len(products) == 2