Skip to content
Django Admin File Wiget for Zappa based admin panels
Branch: master
Clone or download
Fetching latest commit…
Cannot retrieve the latest commit at this time.
Permalink
Type Name Latest commit message Commit time
Failed to load latest commit information.
.github
example
tests
zappa_file_widget
.editorconfig initial commit Aug 26, 2016
.gitignore
.travis.yml
AUTHORS.rst
CONTRIBUTING.rst
HISTORY.rst
LICENSE initial commit Aug 26, 2016
MANIFEST.in
Makefile
README.md updated readme Oct 9, 2016
requirements.txt
requirements_dev.txt initial commit Aug 26, 2016
requirements_test.txt
runtests.py
setup.cfg Bump version: 0.1.4 → 0.1.5 Oct 9, 2016
setup.py
tox.ini

README.md

============================= Django Zappa File Widget

pypi-version

Django Admin File Wiget for django-zappa based admin panels

Quickstart

Install Django Zappa File Widget::

pip install zappa-file-widget

Then use it in a project::

settings.py

INSTALLED_APPS += "zappa_file_widget"

models.py

from django.db import models


class Order(models.Model):
    attachment = models.FileField(upload_to="media/") # file size < 1 MB
    ordered_by = models.CharField(max_length=20)

    def __unicode__(self):
        return unicode(self.attachment)

admin.py

from django import forms
from django.contrib import admin

from zappa_file_widget.file_widget import FileWidget
from django_custom_admin.models import Order


class OrderForm(forms.ModelForm):
    class Meta:
        widgets = {
            'attachment': FileWidget(), 
        }


class OrderAdmin(admin.ModelAdmin):
    form = OrderForm


admin.site.register(Order, OrderAdmin)

Zappa URL Widget:

As AWS API Gateway has char limit on request payload we can't send a file size more that 1 MB. We have implemented client size solution to upload files direct to s3 and save the URL in Server

models.py

from django.db import models


class Order(models.Model):
    attachement2 = models.URLField() # file size >= 1 MB
    ordered_by = models.CharField(max_length=20)

    def __unicode__(self):
        return unicode(self.attachment)

admin.py

from django import forms
from django.contrib import admin

from zappa_file_widget.url_widget import URLWidget
from django_custom_admin.models import Order


class OrderForm(forms.ModelForm):
    class Meta:
        widgets = {
            'attachment2':  URLWidget(upload_to="child_profile_pic/"), 
        }


class OrderAdmin(admin.ModelAdmin):
    form = OrderForm


admin.site.register(Order, OrderAdmin)

Sample S3 Bucket ACLs to support Uploads from java script sdk / clients

<?xml version="1.0" encoding="UTF-8"?>
<CORSConfiguration xmlns="http://s3.amazonaws.com/doc/2006-03-01/">
    <CORSRule>
        <AllowedOrigin>*</AllowedOrigin>
        <AllowedMethod>GET</AllowedMethod>
        <MaxAgeSeconds>3000</MaxAgeSeconds>
        <AllowedHeader>Authorization</AllowedHeader>
    </CORSRule>
    <CORSRule>
        <AllowedOrigin>*</AllowedOrigin>
        <AllowedMethod>HEAD</AllowedMethod>
        <AllowedMethod>GET</AllowedMethod>
        <AllowedMethod>PUT</AllowedMethod>
        <AllowedMethod>POST</AllowedMethod>
        <AllowedMethod>DELETE</AllowedMethod>
        <ExposeHeader>ETag</ExposeHeader>
        <ExposeHeader>x-amz-meta-custom-header</ExposeHeader>
        <AllowedHeader>*</AllowedHeader>
    </CORSRule>
</CORSConfiguration>

Common Configuration:

settings.py

AWS_ACCESS_KEY_ID = os.environ.get("AWS_ACCESS_KEY_ID")
AWS_SECRET_ACCESS_KEY = os.environ.get("AWS_SECRET_ACCESS_KEY")
AWS_CLOUDFRONT_DOMAIN = os.environ.get("AWS_CLOUDFRONT_DOMAIN")
AWS_STORAGE_BUCKET_NAME = os.environ.get("AWS_STORAGE_BUCKET_NAME")

Example:

git clone https://github.com/anush0247/zappa-file-widget
cd zappa-file-widget/example
mkvirtualenv zappa_file_widget
pip install -r requirements.txt
python manage.py migrate
python manage.py createsuperuser
python manage.py runserver

Point your browser at : http://127.0.0.1:8000/admin/example/order/

Other Projects:

Credits

Tools used in rendering this package:

You can’t perform that action at this time.