rb-commons 0.7.2__py3-none-any.whl → 0.7.4__py3-none-any.whl
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- rb_commons/orm/managers.py +45 -0
- {rb_commons-0.7.2.dist-info → rb_commons-0.7.4.dist-info}/METADATA +1 -1
- {rb_commons-0.7.2.dist-info → rb_commons-0.7.4.dist-info}/RECORD +5 -5
- {rb_commons-0.7.2.dist-info → rb_commons-0.7.4.dist-info}/WHEEL +0 -0
- {rb_commons-0.7.2.dist-info → rb_commons-0.7.4.dist-info}/top_level.txt +0 -0
rb_commons/orm/managers.py
CHANGED
@@ -254,6 +254,49 @@ class BaseManager(Generic[ModelType]):
|
|
254
254
|
self.filters.append(or_(*or_clauses))
|
255
255
|
return self
|
256
256
|
|
257
|
+
def exclude(self, *expressions: Any, **lookups: Any) -> "BaseManager[ModelType]":
|
258
|
+
"""
|
259
|
+
Exclude records that match the given conditions.
|
260
|
+
This is the opposite of filter() - it adds NOT conditions.
|
261
|
+
|
262
|
+
Args:
|
263
|
+
*expressions: Q objects, QJSON objects, or SQLAlchemy expressions
|
264
|
+
**lookups: Field lookups (same format as filter())
|
265
|
+
|
266
|
+
Returns:
|
267
|
+
BaseManager instance for method chaining
|
268
|
+
|
269
|
+
Example:
|
270
|
+
# Exclude users with specific names
|
271
|
+
manager.exclude(name="John", email__contains="test")
|
272
|
+
|
273
|
+
# Exclude using Q objects
|
274
|
+
manager.exclude(Q(age__lt=18) | Q(status="inactive"))
|
275
|
+
|
276
|
+
# Exclude using QJSON
|
277
|
+
manager.exclude(QJSON("metadata", "type", "eq", "archived"))
|
278
|
+
"""
|
279
|
+
self._filtered = True
|
280
|
+
|
281
|
+
for k, v in lookups.items():
|
282
|
+
root = k.split("__", 1)[0]
|
283
|
+
if hasattr(self.model, root):
|
284
|
+
attr = getattr(self.model, root)
|
285
|
+
if hasattr(attr, "property") and isinstance(attr.property, RelationshipProperty):
|
286
|
+
self._joins.add(root)
|
287
|
+
|
288
|
+
lookup_expr = self._parse_lookup(k, v)
|
289
|
+
self.filters.append(~lookup_expr)
|
290
|
+
|
291
|
+
for expr in expressions:
|
292
|
+
if isinstance(expr, Q) or isinstance(expr, QJSON):
|
293
|
+
q_expr = self._q_to_expr(expr)
|
294
|
+
self.filters.append(~q_expr)
|
295
|
+
else:
|
296
|
+
self.filters.append(~expr)
|
297
|
+
|
298
|
+
return self
|
299
|
+
|
257
300
|
def limit(self, value: int) -> "BaseManager[ModelType]":
|
258
301
|
self._limit = value
|
259
302
|
return self
|
@@ -380,6 +423,7 @@ class BaseManager(Generic[ModelType]):
|
|
380
423
|
stmt = stmt.where(and_(*self.filters))
|
381
424
|
|
382
425
|
result = await self.session.execute(stmt)
|
426
|
+
self._reset_state()
|
383
427
|
return int(result.scalar_one())
|
384
428
|
|
385
429
|
async def paginate(self, limit: int = 10, offset: int = 0, relations: Optional[Sequence[str]] = None):
|
@@ -503,6 +547,7 @@ class BaseManager(Generic[ModelType]):
|
|
503
547
|
.limit(1)
|
504
548
|
)
|
505
549
|
result = await self.session.execute(stmt)
|
550
|
+
self._reset_state()
|
506
551
|
return result.scalars().first() is not None
|
507
552
|
|
508
553
|
def has_relation(self, relation_name: str):
|
@@ -13,7 +13,7 @@ rb_commons/http/consul.py,sha256=Ioq72VD1jGwoC96set7n2SgxN40olzI-myA2lwKkYi4,186
|
|
13
13
|
rb_commons/http/exceptions.py,sha256=EGRMr1cRgiJ9Q2tkfANbf0c6-zzXf1CD6J3cmCaT_FA,1885
|
14
14
|
rb_commons/orm/__init__.py,sha256=47DEQpj8HBSa-_TImW-5JCeuQeRkm5NMpJWZG3hSuFU,0
|
15
15
|
rb_commons/orm/exceptions.py,sha256=1aMctiEwrPjyehoXVX1l6ML5ZOhmDkmBISzlTD5ey1Y,509
|
16
|
-
rb_commons/orm/managers.py,sha256=
|
16
|
+
rb_commons/orm/managers.py,sha256=HXFOSeWH34QmvGMLnAS00HKBYKckpk5aSMdxU6TugPI,21314
|
17
17
|
rb_commons/orm/services.py,sha256=71eRcJ4TxZvzNz-hLXo12X4U7PGK54ZfbLAb27AjZi8,1589
|
18
18
|
rb_commons/permissions/__init__.py,sha256=47DEQpj8HBSa-_TImW-5JCeuQeRkm5NMpJWZG3hSuFU,0
|
19
19
|
rb_commons/permissions/role_permissions.py,sha256=4dV89z6ggzLqCCiFYlMp7kQVJRESu6MHpkT5ZNjLo6A,1096
|
@@ -22,7 +22,7 @@ rb_commons/schemes/jwt.py,sha256=ZKLJ5D3fcEmEKySjzbxEgUcza4K-oPoHr14_Z0r9Yic,249
|
|
22
22
|
rb_commons/schemes/pagination.py,sha256=8VZW1wZGJIPR9jEBUgppZUoB4uqP8ORudHkMwvEJSxg,1866
|
23
23
|
rb_commons/utils/__init__.py,sha256=47DEQpj8HBSa-_TImW-5JCeuQeRkm5NMpJWZG3hSuFU,0
|
24
24
|
rb_commons/utils/media.py,sha256=J2Zi0J28DhcVQVzt-myNNVuzj9Msaetul53VjZtdDdc,820
|
25
|
-
rb_commons-0.7.
|
26
|
-
rb_commons-0.7.
|
27
|
-
rb_commons-0.7.
|
28
|
-
rb_commons-0.7.
|
25
|
+
rb_commons-0.7.4.dist-info/METADATA,sha256=svR3AJDwNqIOlhSRWTzc-UeFaAmkbskkYFudWvpcuww,6570
|
26
|
+
rb_commons-0.7.4.dist-info/WHEEL,sha256=_zCd3N1l69ArxyTb8rzEoP9TpbYXkqRFSNOD5OuxnTs,91
|
27
|
+
rb_commons-0.7.4.dist-info/top_level.txt,sha256=HPx_WAYo3_fbg1WCeGHsz3wPGio1ucbnrlm2lmqlJog,11
|
28
|
+
rb_commons-0.7.4.dist-info/RECORD,,
|
File without changes
|
File without changes
|