kiddouk / redisco

A Python Library for Simple Models and Containers Persisted in Redis
MIT License
438 stars 78 forks source link

add __getitem__ to ModelBase for [] call syntax #29

Closed boostbob closed 8 years ago

boostbob commented 11 years ago

Hi, i have add \_\_getitem\_\_ method for ModelBase class, so i can to write Model[id] instead of Model.objects.get_by_id(), Although the modification is small, but I think it is useful. Already test passed.

Thank you for create this repo, it's really nice.

from redisco import models

class Person(models.Model):
    name = models.Attribute(required=True, unique=True, indexed=True)

Person(name="debugger").save()
p = Person.objects.filter(name="debugger").first()

print p.id
print Person.objects.get_by_id(p.id)
# short code for above
print Person[p.id]
stuaxo commented 8 years ago

@kiddouk this looks like it would pass if build was retriggered.

kiddouk commented 8 years ago

Just retested this locally. works.