Skip to main content

The small frameworks that helps to write reusable django apps

Project description

https://badge.fury.io/py/django-generic-helpers.png https://travis-ci.org/marazmiki/django-generic-helpers.png?branch=master https://coveralls.io/repos/marazmiki/django-generic-helpers/badge.png?branch=master https://pypip.in/d/django-generic-helpers/badge.png

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 the generic_helpers app into 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


Download files

Download the file for your platform. If you're not sure which to choose, learn more about installing packages.

Source Distributions

django-generic-helpers-0.3.1.zip (11.0 kB view hashes)

Uploaded Source

django-generic-helpers-0.3.1.tar.gz (4.8 kB view hashes)

Uploaded Source

django-generic-helpers-0.3.1.tar.bz2 (5.0 kB view hashes)

Uploaded Source

Supported by

AWS AWS Cloud computing and Security Sponsor Datadog Datadog Monitoring Fastly Fastly CDN Google Google Download Analytics Microsoft Microsoft PSF Sponsor Pingdom Pingdom Monitoring Sentry Sentry Error logging StatusPage StatusPage Status page