The small frameworks that helps to write reusable django apps
Project description
This app provides some snippets (such as abstract models and managers with some useful methods) to simplyfy creation of another pluggable apps.
The license is MIT.
Installation
pip install django-generic-helpers
After you can add app ‘generic_helpers’ to your INSTALLED_APPS. If you aren’t want to run test, you can skip this step.
Usage
To use this app, just import GenericRelationModel class from generic_helpers.models package and inherit your model from it:
from django.db import models from generic_helpers.models import GenericRelationModel
- class MyModel(GenericRelationModel):
title = models.CharField(max_length=255)
Now MyModel class has content_object attribute and you can create MyModel instances using generic relation:
>>> from django.contrib.auth.models import User >>> user = User.objects.get(pk=1) >>> >>> my_model = MyModel.objects.create( ... title = 'title', ... content_object = user, ... ) >>>
In this example how you can see we have used User.
Also your model manager has a get_for_object method for quick filtering by content_object complex field:
>>> from django.contrib.auth.models import User >>> user = User.objects.get(pk=1) >>> >>> models_for_user = MyModel.objects.get_for_object(user) >>>
Contributing
If you’ve found a bug, implemented a feature and think it is useful, or you’ve own pluggable app and want to use django-generic-helpers in it, then please consider contributing. Patches, pull requests or just suggestions are welcome!
Project details
Release history Release notifications | RSS feed
Download files
Download the file for your platform. If you're not sure which to choose, learn more about installing packages.
Source Distributions
Hashes for django-generic-helpers-0.2.2.zip
Algorithm | Hash digest | |
---|---|---|
SHA256 | 8badb24d1f55cda2fc0687df09b8cf103c4eca92d44d65d7933e75535f17938e |
|
MD5 | 45e834947d62c7b59c9cd46ec95a3c2a |
|
BLAKE2b-256 | 883db12513d84a98ec158512ce13fbf6d9b64232f901ce1f3c4090eb10262954 |
Hashes for django-generic-helpers-0.2.2.tar.gz
Algorithm | Hash digest | |
---|---|---|
SHA256 | 4b04d4858821428df4a42e879bf52b0fb3244f4db0cacb0a2a317fdbd5ccf9f0 |
|
MD5 | 449fb9234731df712621214de5672152 |
|
BLAKE2b-256 | 657a608d680b45281b6974886997b1288e8552e2a7310e9c10b698abf66d1552 |
Hashes for django-generic-helpers-0.2.2.tar.bz2
Algorithm | Hash digest | |
---|---|---|
SHA256 | 7d76e6d7f0249d85b5a117179a83d3a45e175392548cff7605b66326a5386a68 |
|
MD5 | f1ad1a6571fdd9e57d7e44968cf07325 |
|
BLAKE2b-256 | 1ac55c3f0d9d13d7f7a24d73ca3a829a207f060b241df22fcfbc65f0e68145f8 |