Ecosyste.ms: Awesome
An open API service indexing awesome lists of open source software.
https://github.com/jpablo/django-orm-lambdas
A LINQ-esque Manager for Django models
https://github.com/jpablo/django-orm-lambdas
Last synced: 25 days ago
JSON representation
A LINQ-esque Manager for Django models
- Host: GitHub
- URL: https://github.com/jpablo/django-orm-lambdas
- Owner: jpablo
- Created: 2011-06-05T23:13:30.000Z (over 13 years ago)
- Default Branch: master
- Last Pushed: 2011-06-29T18:11:05.000Z (over 13 years ago)
- Last Synced: 2024-11-14T00:53:40.715Z (2 months ago)
- Language: Python
- Homepage:
- Size: 97.7 KB
- Stars: 5
- Watchers: 2
- Forks: 0
- Open Issues: 0
-
Metadata Files:
- Readme: README.md
Awesome Lists containing this project
README
# LambdaManager
LambdaManager extends the regular django.db.models.Manager with one function:
```python
where(lambda x: ...)
```that can be used like this:
## Example
```python
# in models.py:from django.db import models
from lambda_manager import LambdaManagerclass Poll(models.Model):
question = models.CharField(max_length=200)
pub_date = models.DateTimeField('date published')objects = LambdaManager()
class Choice(models.Model):
poll = models.ForeignKey(Poll)
choice = models.CharField(max_length=200)
votes = models.IntegerField()
anumber = models.IntegerField()objects = LambdaManager()
```
```python
# elsewhere:from models import Choice
Choice.objects.where(lambda c: c.votes >= 1)
Choice.objects.where(lambda c: c.votes != 1)
Choice.objects.where(lambda c: c.poll.question.exact('aaa'))
Choice.objects.where(lambda c: c.poll.question.contains('aa'))
Choice.objects.where(lambda c: c.votes == c.anumber)
Choice.objects.where(lambda c: c.votes > c.anumber)
Choice.objects.where(lambda x: x.votes < x.votes + 1)
Choice.objects.where(lambda x: x.votes < x.votes + x.votes + 2)
```## TODO:
Implement other arithmetic operators: *, -, /
```python
Entry.objects.filter(n_comments__gt=F('n_pingbacks') * 2)
```