yohanboniface/redis-limpyd — pull request #61 by twidi (2013-01-05 14:19:15+00:00)
Title: Enhance contrib.related

A short list of commit to enhance the related stuff in contrib.

- make the main metaclass `MetaRedisProxy` work silently for classes not inheriting from `RedisProxyCommand` (to easier create mixins, as in python, all classes used in multi-inheritance must use same base metaclasses)

- calling M2M related fields return a collection, to be able to do:

```python
class Person(RelatedModel):
name = PKField()

class Group(RelatedModel):
name = PKField()
members = M2MSetField(Person, related_name='membership')

person1 = Person(name='person1')
person2 = Person(name='person2')
group1 = Group(name='group1')
group2 = Group(name='group2')

group1.members.sadd(person1, person2)
group2.members.sadd(person1, person2)

# A RelatedColleciton that return a collection with set(['person1', 'person2'])
person1.membership()
# A M2MSetField call, that return a collection with set(['group1', 'group2'])
group1.members()
```

- ability to inherit form `CollectionManager` and choose the one to use in a `RedisModel`

- ability to inherit from `RelatedCollection` and choose the one to use in a `RelatedModel`

- add a way to get the instance from a FK field:

```python
class Person(RelatedModel):
name = PKField()

class Group(RelatedModel):
name = PKField()
owner = FKStringField(Person, related_name='groups')

person1 = Person(name='person1')
group1 = Group(name='group1', owner=person1)

group1.owner.get() # return the pk of person1
group1.owner.instance() # return person1 (a copy of)
```

- use "collection" to retrieve related objects of a M2M fields, for more consistency:

```python
# previously:
obj.field(**filters)

# now, in addition to above:
obj.field.collection(**filters)
```

- make the `from_python` accepts instance in addition to pk (by converting instances to their pks)

```python
# previously
a_group.owner.hset(an_account.get_pk())

# now, in addition to above:
a_group.owner.hset(an_account)