Skip to main content

Add-another pop-ups a la django-admin.

Project description

https://badge.fury.io/py/django_popcorn.png https://travis-ci.org/alixedi/django_popcorn.png?branch=master https://pypip.in/d/django_popcorn/badge.png

Add-another pop-ups a la django-admin.

The popup views are implemented using a mixin to the generic CreateView. Also, the popups now support permissions. As a result, a user will onle get the ‘add-another’ link next to a ForeignKey if he has the add permission for the target model.

Installation

Get it from the cheeseshop:

pip install django_coffee_table

Usage

Read on:

  1. Include the following in your INSTALLED_APPS settings:

    'popcorn',
    'reform',
    'bootstrap_toolkit',
    'widget_tweaks',
    
  2. Uncomment django.contrib.admin in the INSTALLED_APPS settings.

  3. Add this to your settings.py (If you do not already have it):

    TEMPLATE_CONTEXT_PROCESSORS = (
        "django.contrib.auth.context_processors.auth",
        "django.core.context_processors.debug",
        "django.core.context_processors.i18n",
        "django.core.context_processors.media",
        "django.core.context_processors.static",
        "django.contrib.messages.context_processors.messages",
        "django.core.context_processors.request",
        "popcorn.context_processors.admin_media_prefix",
    )
    
  4. Add the following to your base.html template:

    <script src="{{ ADMIN_MEDIA_PREFIX }}js/admin/RelatedObjectLookups.js"></script>
    
  5. Write a few views - use PopcornMixin for popup views:

    class CreateUser(CreateView):
        model = User
    
    class PopcornGroup(PopcornMixin, CreateView):
        model = Group
    
    class PopcornPermission(PopcornMixin, CreateView):
        model = Permission
    
  6. Use the utility function to generate popcorn urls:

    urlpatterns = patterns('',
        url(r'^$', CreateUser.as_view(), name='auth_user_create'),
        url(r'^admin/', include(admin.site.urls)),
    )
    
    urlpatterns += get_popcorn_urls([PopcornGroup, PopcornPermission])
    
  7. Render your forms using django_reform reform tag:

    {% reform form %}
    
  8. Open up a browser, type-in http://localhost:8000. You will not see add-another links next to ForeignKey fields.

  9. Log-in using the admin interface, visit http://localhost:8000 again. The form now should have add-another links next to the ForeignKey fields.

  10. If you are having any problems, please check out the demo project for a working implementation.

History

0.1.0 (2013-12-2)

  • First release on PyPI.

0.2.0 (2013-12-9)

  • Added support for permissions.

Project details


Download files

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

Filename, size & hash SHA256 hash help File type Python version Upload date
django_popcorn-0.2.1.tar.gz (7.5 kB) Copy SHA256 hash SHA256 Source None

Supported by

Elastic Elastic Search Pingdom Pingdom Monitoring Google Google BigQuery Sentry Sentry Error logging AWS AWS Cloud computing DataDog DataDog Monitoring Fastly Fastly CDN SignalFx SignalFx Supporter DigiCert DigiCert EV certificate StatusPage StatusPage Status page