mirror of
https://github.com/jazzband/django-ddp.git
synced 2026-05-03 21:24:47 +00:00
Add dddp.models.get_object(model, meteor_id) method, make get_meteor_id(obj) return None where obj is None.
This commit is contained in:
parent
756a65474d
commit
befa57b8a3
1 changed files with 10 additions and 0 deletions
|
|
@ -12,6 +12,8 @@ from dddp import meteor_random_id
|
|||
@transaction.atomic
|
||||
def get_meteor_id(obj):
|
||||
"""Return an Alea ID for the given object."""
|
||||
if obj is None:
|
||||
return None
|
||||
# Django model._meta is now public API -> pylint: disable=W0212
|
||||
meta = obj._meta
|
||||
obj_pk = str(obj.pk)
|
||||
|
|
@ -42,6 +44,14 @@ def get_object_id(model, meteor_id):
|
|||
).values_list('object_id', flat=True).get()
|
||||
|
||||
|
||||
@transaction.atomic
|
||||
def get_object(model, meteor_id):
|
||||
"""Return an object for the given meteor_id."""
|
||||
return model.objects.get(
|
||||
pk=get_object_id(model, meteor_id),
|
||||
)
|
||||
|
||||
|
||||
class AleaIdField(models.CharField):
|
||||
|
||||
"""CharField that generates its own values using Alea PRNG before INSERT."""
|
||||
|
|
|
|||
Loading…
Reference in a new issue