nookskill / django-excel-tools

Django helper for importing data from excel

Geek Repo:Geek Repo

Github PK Tool:Github PK Tool

Django Excel Tools

https://travis-ci.org/NorakGithub/django-excel-tools.svg?branch=master

Common function when working with excel.

Requirements

Installations

Install django-excel-tools

pip install django-excel-tools

Usage

Class declaration

from django_excel_tools import serializers


class OrderExcelSerializer(serializers.ExcelSerializers):
    REGION_CHOICES = ('Central', 'North', 'East', 'West', 'South')
    product_name = serializers.CharField(max_length=100, verbose_name='Product Name')
    quantity = serializers.IntegerField(verbose_name='Quantity', blank=True, default=0)
    price = serializers.IntegerField(verbose_name='Price')
    region = serializers.CharField(max_length=10, verbose_name='Region', choices=REGION_CHOICES)
    transaction_date = serializers.DateField(date_format='%Y-%m-%d', date_format_verbose='YYYY-MM-DD',
                                             verbose_name='Transaction Date')

    class Meta:
        start_index = 1
        fields = ('product_name', 'quantity', 'price', 'region', 'transaction_date')

Class initialization

from openpyxl import load_workbook


def import_order():
    workbook = load_workbook(file)  # Create workbook from file. Used openpyxl
    worksheet = workbook.worksheets[0]
    serializer = OrderExcelSerializer(worksheet=worksheet, **kwargs)

Credits

This package was created with Cookiecutter and the audreyr/cookiecutter-pypackage project template.

About

Django helper for importing data from excel

License:MIT License


Languages

Language:Python 93.7%Language:Makefile 6.3%