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.3.zip
(7.4 kB
view details)
File details
Details for the file Flask-DjangoQuery-0.2.3.zip
.
File metadata
- Download URL: Flask-DjangoQuery-0.2.3.zip
- Upload date:
- Size: 7.4 kB
- Tags: Source
- Uploaded using Trusted Publishing? No
File hashes
Algorithm | Hash digest | |
---|---|---|
SHA256 | be05737ebc63612aa3c2b85fad9e83c8bee29d086d9f82c527959a3544b07fc0 |
|
MD5 | dd18d367be9f8a91882318a9bf2a0afc |
|
BLAKE2b-256 | f350533bb89f4f1f3cacc944392f35b4a3da59da99164a02b2a5574b245458d0 |
File details
Details for the file Flask-DjangoQuery-0.2.3.tar.gz
.
File metadata
- Download URL: Flask-DjangoQuery-0.2.3.tar.gz
- Upload date:
- Size: 4.6 kB
- Tags: Source
- Uploaded using Trusted Publishing? No
File hashes
Algorithm | Hash digest | |
---|---|---|
SHA256 | 0d7587a0a3f4de0d74c38871bb8740df0b5479ceb4e0c1ea12c53b33e878e838 |
|
MD5 | 5ea8aed44a22e13bf323eef068dddbe5 |
|
BLAKE2b-256 | 4e0d4aecb68a0ff44a01533f7a7d83dc4192c4c1407b3af0fa99c6c761df47e9 |