offline / django-annoying
This is django application that try to eliminate annoying things in Django framework.
Clone this repository (size: 42.7 KB): HTTPS / SSH
$ hg clone http://bitbucket.org/offline/django-annoying/
| commit 8: | e587b6a99502 |
| parent 7: | 64ef7036be50 |
| branch: | default |
AutoOneToOne field added
offline
14 months ago
14 months ago
Changed (Δ1.5 KB):
raw changeset »
annoying/fields.py (20 lines added, 0 lines removed)
setup.py (23 lines added, 1 lines removed)
Up to file-list annoying/fields.py:
1 |
from django.db.models import OneToOneField |
|
2 |
from django.db.models.fields.related import SingleRelatedObjectDescriptor |
|
3 |
||
4 |
||
5 |
class AutoSingleRelatedObjectDescriptor(SingleRelatedObjectDescriptor): |
|
6 |
def __get__(self, instance, instance_type=None): |
|
7 |
try: |
|
8 |
return super(AutoSingleRelatedObjectDescriptor, self).__get__(instance, instance_type) |
|
9 |
except self.related.model.DoesNotExist: |
|
10 |
obj = self.related.model(**{self.related.field.name: instance}) |
|
11 |
obj.save() |
|
12 |
return obj |
|
13 |
||
14 |
class AutoOneToOneField(OneToOneField): |
|
15 |
''' |
|
16 |
OneToOneField creates related object on first call if it doesnt exists yet. |
|
17 |
''' |
|
18 |
def contribute_to_related_class(self, cls, related): |
|
19 |
setattr(cls, related.get_accessor_name(), AutoSingleRelatedObjectDescriptor(related)) |
|
20 |
1 |
1 |
from setuptools import setup, find_packages |
2 |
2 |
setup( |
3 |
3 |
name = "django-annoying", |
4 |
version = "0. |
|
4 |
version = "0.3", |
|
5 |
5 |
packages = find_packages(), |
6 |
6 |
author = "Anderson", |
7 |
7 |
author_email = "self.anderson@gmail.com", |
8 |
8 |
description = "This is django application that try to eliminate annoying things in Django framework.", |
9 |
long_description = """ |
|
10 |
**Features:** |
|
11 |
||
12 |
- render_to decorator - reduce typing in django views. |
|
13 |
- signals decorator - allow use signals as decorators. |
|
14 |
- get_object_or_None function - similar to get_object_or_404, but returns None if object not found. |
|
15 |
- AutoOneToOne field - creates related object on first call if it doesnt exists yet. |
|
16 |
||
17 |
||
18 |
||
19 |
**Installation instruction:** |
|
20 |
||
21 |
- Copy annoying directory to your django project or put in on PYTHONPATH |
|
22 |
- Also you can run sudo python setup.py install or sudo easy_install django-annoying |
|
23 |
||
24 |
||
25 |
||
26 |
**Download:** |
|
27 |
||
28 |
- hg clone http://hg.assembla.com/django-annoying |
|
29 |
||
30 |
""", |
|
9 |
31 |
license = "BSD", |
10 |
32 |
keywords = "django", |
11 |
33 |
url = "http://www.assembla.com/spaces/django-annoying", |
