add callable excecution and test for default value, update readme with exclude, bump version
This commit is contained in:
@ -82,6 +82,9 @@ notes = await Note.objects.filter(completed=True).all()
|
|||||||
# exact, iexact, contains, icontains, lt, lte, gt, gte, in
|
# exact, iexact, contains, icontains, lt, lte, gt, gte, in
|
||||||
notes = await Note.objects.filter(text__icontains="mum").all()
|
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()
|
# .get()
|
||||||
note = await Note.objects.get(id=1)
|
note = await Note.objects.get(id=1)
|
||||||
|
|
||||||
|
|||||||
@ -26,7 +26,7 @@ class UndefinedType: # pragma no cover
|
|||||||
|
|
||||||
Undefined = UndefinedType()
|
Undefined = UndefinedType()
|
||||||
|
|
||||||
__version__ = "0.3.0"
|
__version__ = "0.3.1"
|
||||||
__all__ = [
|
__all__ = [
|
||||||
"Integer",
|
"Integer",
|
||||||
"BigInteger",
|
"BigInteger",
|
||||||
|
|||||||
@ -41,7 +41,10 @@ class BaseField:
|
|||||||
@classmethod
|
@classmethod
|
||||||
def get_default(cls) -> Any:
|
def get_default(cls) -> Any:
|
||||||
if cls.has_default():
|
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
|
@classmethod
|
||||||
def has_default(cls) -> bool:
|
def has_default(cls) -> bool:
|
||||||
|
|||||||
@ -1,4 +1,5 @@
|
|||||||
import asyncio
|
import asyncio
|
||||||
|
from datetime import datetime
|
||||||
|
|
||||||
import databases
|
import databases
|
||||||
import pydantic
|
import pydantic
|
||||||
@ -43,6 +44,7 @@ class Product(ormar.Model):
|
|||||||
name: ormar.String(max_length=100)
|
name: ormar.String(max_length=100)
|
||||||
rating: ormar.Integer(minimum=1, maximum=5)
|
rating: ormar.Integer(minimum=1, maximum=5)
|
||||||
in_stock: ormar.Boolean(default=False)
|
in_stock: ormar.Boolean(default=False)
|
||||||
|
last_delivery: ormar.Date(default=datetime.now)
|
||||||
|
|
||||||
|
|
||||||
@pytest.fixture(scope="module")
|
@pytest.fixture(scope="module")
|
||||||
@ -158,6 +160,7 @@ async def test_model_filter():
|
|||||||
assert product.pk is not None
|
assert product.pk is not None
|
||||||
assert product.name == "T-Shirt"
|
assert product.name == "T-Shirt"
|
||||||
assert product.rating == 5
|
assert product.rating == 5
|
||||||
|
assert product.last_delivery == datetime.now().date()
|
||||||
|
|
||||||
products = await Product.objects.all(rating__gte=2, in_stock=True)
|
products = await Product.objects.all(rating__gte=2, in_stock=True)
|
||||||
assert len(products) == 2
|
assert len(products) == 2
|
||||||
|
|||||||
Reference in New Issue
Block a user