Django like query for Flask-SQLAlchemy
Project description
Flask-DjangoQuery
=================
A module that implements a more Django like interface for Flask-SQLAlchemy query objects. It's still API compatible with the regular one but extends it with Djangoisms.
## Installation
Install Flask-DjangoQuery with pip:
$ [sudo] pip install Flask-DjangoQuery
Install Flask-DjangoQuery with easy_install:
$ [sudo] easy_install Flask-DjangoQuery
Or you can clone or download it then:
```bash
cd Flask-DjangoQuery
python setup.py install
```
## Usage
```python
from flask import Flask
from flask.ext.djangoquery import SQLAlchemy
app = Flask(__name__)
db = SQLAlchemy()
db.init_app(app)
```
Then you can use it just like [Flask-SQLAlchemy](https://github.com/mitsuhiko/flask-sqlalchemy) while have a more *Django like* `filter_by`, `exclude_by` and `order_by` interface.
### Define a model
```python
class Post(db.Model):
id = db.Column(db.Integer, primary_key=True)
pub_date = db.Column(db.Datetime)
title = db.Column(db.String(50))
```
## Example queries
```python
Post.query.filter_by(pub_date__year=2008)
Post.query.exclude_by(id=42)
Post.query.filter_by(title__contains='something')
Post.query.order_by('-post__pub_date')
```
For more please view the codes of [flask_djangoquery.py](flask_djangoquery.py)
=================
A module that implements a more Django like interface for Flask-SQLAlchemy query objects. It's still API compatible with the regular one but extends it with Djangoisms.
## Installation
Install Flask-DjangoQuery with pip:
$ [sudo] pip install Flask-DjangoQuery
Install Flask-DjangoQuery with easy_install:
$ [sudo] easy_install Flask-DjangoQuery
Or you can clone or download it then:
```bash
cd Flask-DjangoQuery
python setup.py install
```
## Usage
```python
from flask import Flask
from flask.ext.djangoquery import SQLAlchemy
app = Flask(__name__)
db = SQLAlchemy()
db.init_app(app)
```
Then you can use it just like [Flask-SQLAlchemy](https://github.com/mitsuhiko/flask-sqlalchemy) while have a more *Django like* `filter_by`, `exclude_by` and `order_by` interface.
### Define a model
```python
class Post(db.Model):
id = db.Column(db.Integer, primary_key=True)
pub_date = db.Column(db.Datetime)
title = db.Column(db.String(50))
```
## Example queries
```python
Post.query.filter_by(pub_date__year=2008)
Post.query.exclude_by(id=42)
Post.query.filter_by(title__contains='something')
Post.query.order_by('-post__pub_date')
```
For more please view the codes of [flask_djangoquery.py](flask_djangoquery.py)
Project details
Download files
Download the file for your platform. If you're not sure which to choose, learn more about installing packages.
Source Distributions
Flask-DjangoQuery-0.2.2.zip
(7.4 kB
view details)
File details
Details for the file Flask-DjangoQuery-0.2.2.zip
.
File metadata
- Download URL: Flask-DjangoQuery-0.2.2.zip
- Upload date:
- Size: 7.4 kB
- Tags: Source
- Uploaded using Trusted Publishing? No
File hashes
Algorithm | Hash digest | |
---|---|---|
SHA256 | c2a363f0ad1dba24371d84a45f90ad43e3c36098a1cee8bcb69e230ad9da14a8 |
|
MD5 | 5c486e864a936ff303dd900a2238a23d |
|
BLAKE2b-256 | 9647e8300487a0b466f80e6bfd003449257a6eb8a75f57734a366066f3229445 |
File details
Details for the file Flask-DjangoQuery-0.2.2.tar.gz
.
File metadata
- Download URL: Flask-DjangoQuery-0.2.2.tar.gz
- Upload date:
- Size: 4.5 kB
- Tags: Source
- Uploaded using Trusted Publishing? No
File hashes
Algorithm | Hash digest | |
---|---|---|
SHA256 | c0519abe0ea9e2af76397ff5f4ff10a690e907b57bbef4149ca16851b7977f4c |
|
MD5 | 6ea57dca80e5becb2f37e914029b3026 |
|
BLAKE2b-256 | d68a09cfbe96e885f65a1b7f46b12fc69184d7dc95b172b613af7113c2cc8436 |