Metadata-Version: 1.1
Name: django-attrs
Version: 0.0.1
Summary: Django model attributes
Home-page: http://pypi.python.org/pypi/django-attrs/
Author: Dino Perovic
Author-email: dino.perovic@gmail.com
License: BSD
Description: django-attrs
        ============
        
        ``django-attrs`` allows you do add dynamic **key / value** attributes to your
        models.
        
        :Version: 0.0.1
        :Download: http://pypi.python.org/pypi/django-attrs/
        :Source: http://github.com/dinoperovic/django-attrs/
        :Dev Status: Pre-Alpha
        
        
        Installation
        ------------
        
        To install ``django-attrs`` with ``pip`` run::
        
            $ pip install -e git://github.com/dinoperovic/django-attrs.git@master#egg=django-attrs
        
        
        Setup
        -----
        
        * Add ``attrs`` to ``INSTALLED_APPS``
        * Add ``url(r'^attrs/', include('attrs.urls'))`` to ``urls.py``
        
        
        Usage
        -----
        
        Models
        ******
        
        Your model should inherit from ``AttrsModel`` and define ``get_attrs_options``
        (optional) to return your attrs options:
        
        .. code:: python
        
            # models.py
            from django.db import models
            from attrs.models import AttrsModel
        
        
            class MyImage(AttrsModel):
                def get_attrs_options(self):
                    return {
                        'title': {
                            'name': 'Title',
                        },
                        'description': {
                            'name': 'Description',
                            'widget': 'textarea',
                        },
                        'size': {
                            'name': 'Size',
                            'choices': (
                                ('small', 'Small'),
                                ('medium', 'Medium'),
                                ('large', 'Large'),
                            ),
                        },
                        'tag': {
                            'name': 'Tag',
                            'max_num': 100,
                        },
                    }
        
        Each entry in your options acts as a field that can be added dynamically.
        If ``get_attrs_options`` is not defined default options will be used.
        you can change the defaults by overriding ``ATTRS_DEFAULT_OPTIONS`` in
        your ``settings.py``.
        
        Admin
        *****
        
        Your admin should inherit from ``AttrsAdmin``:
        
        .. code:: python
        
            # admin.py
            from django.contrib import admin
            from attrs.admin import AttrsAdmin
        
            from .models import MyImage
        
        
            class MyImageAdmin(AttrsAdmin):
                pass
        
            admin.site.register(MyImage, MyImageAdmin)
        
        ``AttrsAdmin`` overrides your ``change_form_template`` and adds attributes
        to inlines.
        
        That's it. You can now add attributes to your model.
        
        
        Alternate usage
        ---------------
        
        Adding attributes to existing models
        ************************************
        
        If you want to add attributes to your model without changing the actual
        **model** and **admin** you can do it using ``register_attrs`` function:
        
        .. code:: python
        
            from attrs.utils import register_attrs
        
            from myapp.models import MyImage
            from myapp.admin import MyImageAdmin
        
            my_image_attrs = {
                'title': {
                    'name': 'Title',
                },
                'description': {
                    'name': 'Description',
                    'widget': 'textarea',
                },
            }
        
            register_attrs(MyImage, MyImageAdmin, my_image_attrs)
        
        
        
        Templatetags
        ------------
        
        To use templatetags you must add  ``{% load attrs_tags %}`` in your template.
        
        get_attrs
        *********
        .. code:: html+django
        
            {% get_attrs my_model as my_model_attrs %}
        
        
        Settings
        --------
        
        Available settings
        ******************
        
        Thease are the defaults you can change by adding the to your settings.py.
        
        * ``ATTRS_CHANGE_FORM_TEMPLATE = 'attrs/change_form.html'``
        * ``ATTRS_FIELD_TEXT_TEMPLATE = 'attrs/fields/text.html'``
        * ``ATTRS_FIELD_SELECT_TEMPLATE = 'attrs/fields/select.html'``
        * ``ATTRS_FIELD_TEXTAREA_TEMPLATE = 'attrs/fields/textarea.html'``
        * ``ATTRS_DEFAULT_OPTIONS = {}``
        
        
        Options format
        **************
        
        Options that are set in ``ATTRS_DEFAULT_OPTIONS``, returned by
        ``get_attrs_options`` or passed into the ``register_attrs`` function
        should be formated as a dictionary like this:
        
        .. code:: python
        
            ATTRS_DEFAULT_OPTIONS = {
                '<field_key>': {
                    'name': '<field_name>',
                },
                '<field_key>': {
                    'name': '<field_name>',
                    'widget': 'textarea'
                },
                '<field_key>': {
                    'name': '<field_name>',
                    'choices': (
                        ('<choice_1>', '<Choice 1>'),
                        ('<choice_2>', '<Choice 2>'),
                        ('<choice_3>', '<Choice 3>'),
                    ),
                },
                '<field_key>': {
                    'name': '<field_name>',
                    'max_num': <number>,
                },
            }
        
        * Each field must at least specify the **name** attribute.
        * Default widget is **text** and can be changed to **textarea**.
        * If choices are specified widget is automatically set to **select**.
        * **max_num** defines how many times field can be specified, defaults to 1.
        
        
        
        
        
Platform: UNKNOWN
Classifier: Development Status :: 2 - Pre-Alpha
Classifier: Environment :: Web Environment
Classifier: Framework :: Django
Classifier: Intended Audience :: Developers
Classifier: Operating System :: OS Independent
Classifier: Programming Language :: Python
Classifier: Topic :: Internet :: WWW/HTTP
