Skip to main content

Django Generic File

Project description

A Generic File Model for all kind of file attachment with AJAX fileupload and drag & drop feature.

  • Attach files to any Model across your project

  • Include file upload field in your django templates using our templatetags

  • Retrieve back the list of files attached to your Object using our templatetags

Installation

pip install django-generic-file

Usage

  1. Add “genericfile” to your INSTALLED_APPS and migrate.

  2. Include following static files in your template:

    <link rel="stylesheet" type="text/css" href="{% static 'genericfile/genericfile.css' %}">
    <script src="{% static 'genericfile/genericfile.js' %}"></script>
  3. At the top of your template load our template tags:

    {% load genericfiletags %}

Then to render your form

  1. In Your Add Form (basically where object is not yet created / unknown):

    <form action='.' method='post'>
        {% csrf_token %}
        {{ form }}
        {% get_genericfile_form %}
        <button type='submit' class="btn blue">Submit</button>
    </form>
    
    # then in POST method of your view,
    from genericfile.views import update_genericfile
    update_genericfile(self.request.POST, self.object)
  2. In Your Edit Form (where object is known):

    <form action='.' method='post'>
        {% csrf_token %}
        {{ form }}
        {% get_genericfile_form host_object=form.instance %}
        <button type='submit' class="btn blue">Submit</button>
    </form>

Options

  1. maxFileCount - to Restrict Number of files:

    {% get_genericfile_form maxFileCount=1 %}
    
    # Default is NoLimit
  2. allowedTypes - to Restrict File types:

    {% get_genericfile_form allowedTypes="jpg,jpeg,png,gif,doc,pdf,zip,html,txt,docx" %}
    
    # Default is AnyFiles

To get the list of files in Details view

{% get_genericfile_list host_object=object as attachments %}
<ul>
  {% for file in attachments %}
    <li><a href="{{file.attachment.url}}" target="_blank">{{file.get_name}}</a></li>
  {% empty %}
    <li>No files found</li>
  {% endfor %}
</ul>

Additional Requirements

Include if you not have included them already in you html file

<link rel="stylesheet" href="https://maxcdn.bootstrapcdn.com/font-awesome/4.4.0/css/font-awesome.min.css">
<script src="https://ajax.googleapis.com/ajax/libs/jquery/1.11.2/jquery.min.js"></script>

Project details


Download files

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

Source Distribution

django-generic-file-0.0.2.zip (18.3 kB view details)

Uploaded Source

Built Distribution

If you're not sure about the file name format, learn more about wheel file names.

django-generic-file-0.0.2.win32.exe (212.0 kB view details)

Uploaded Source

File details

Details for the file django-generic-file-0.0.2.zip.

File metadata

File hashes

Hashes for django-generic-file-0.0.2.zip
Algorithm Hash digest
SHA256 99761f1721038a57ee73fb510ccf3cf7366bbf95c1a50eb297c00ae5d16811e6
MD5 39b932858e4475d56718bd9e16ec2c9f
BLAKE2b-256 8a3739a70f4492361aa97e864e86c71298d665dc5374ef882e6ed35894172fcc

See more details on using hashes here.

File details

Details for the file django-generic-file-0.0.2.win32.exe.

File metadata

File hashes

Hashes for django-generic-file-0.0.2.win32.exe
Algorithm Hash digest
SHA256 19e39f4acf2be5d0c602f1fd093268180a11b59ecd0488f4c8bbdd789cbb17a7
MD5 cf5179c2cc4f3c4ba329770c051e1765
BLAKE2b-256 1dc8ec9b70d37bec7912bee9489ead17dc88079d49153b8f0bd8935fd534ca54

See more details on using hashes here.

Supported by

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