Giter VIP home page Giter VIP logo

django-parser-app's Introduction

django-parser-app

parser_app has been created intending to import Excel file data to django models in a convenient manner. This is a rest_framework based packege and is usuable in many projects.

This package is only compatible with PostgreSQL (tested with PostgreSQL version 13 and 13.3)

Table of Contents

Feel free to contribute in the parser_app. Your contributions are always appreciated!

Quick start


Install the app


  1. Install django-parser-app pip install django-parser-app

Configure Project


  1. Add parser_app and it's dependencies to your INSTALLED_APPS setting like this::

    INSTALLED_APPS = [
        ...
        'parser_app',
        'rest_framework',
        'corsheaders',
    ]
    
  2. Add SITE_URL in setting::

    SITE_URL = 'http://yoursiteurl.com'
    
  3. Implement Django Dependancy Settings:

    Such as:

    MIDDLEWARE = [
        ...
        'django.contrib.sessions.middleware.SessionMiddleware',
        'corsheaders.middleware.CorsMiddleware',
        'django.middleware.common.CommonMiddleware',
        ...
    ]
    
    REST_FRAMEWORK = {
        'DEFAULT_PERMISSION_CLASSES': (
            'rest_framework.permissions.IsAuthenticated',
            'rest_framework.permissions.IsAuthenticatedOrReadOnly',
        ),
        'DEFAULT_AUTHENTICATION_CLASSES': (
            'rest_framework.authentication.SessionAuthentication',
        ),
    }
    
    CORS_ORIGIN_ALLOW_ALL = True
    
  4. parser_app is a api based packege. Include it's URLconf in your project urls.py exactly like below::

    path('api/', include('parser_app.urls')),
    
  5. Run python manage.py migrate to create the parser_app models.

Register Models


  1. Register your models in admin.py file. A demo model and it's admin.py file is given below::

    models.py

    class Area(models.Model):
        code = models.IntegerField(
            null=False, blank=False, unique=True, verbose_name="Location Code", db_column='Code', default=0)
        name = models.CharField(null=False, blank=False,
                                max_length=50, db_column='Name', default='')
        location_type = models.CharField(
            choices=LOCATION_TYPE, default='', max_length=20, verbose_name="Location type", db_column='LocationType')
        parent_code = models.IntegerField(null=True, blank=True, default=0, verbose_name="Parent Code", db_column='ParentCode')
        class Meta:
            verbose_name_plural = "Area"
    
        def __str__(self):
            return str(self.code)
    

    admin.py

    from django.contrib import admin
    
    # Register your models here.
    from .models import Area
    from parser_app.parser import DataParser
    
    DataParser.register_model(Area)
    

Run Project


  1. Start the development server python manage.py runserver 0.0.0.0:8000 and visit http://yoursiteurl:8000/admin/. After logging in, you will see a new model named Registered Models under parser_app section. All your registered models will be listed here.

Import data through Django admin panel


  1. Click on the Registred Models that is located inside parser_app section.
  2. You will see the Area model listed there.
  3. Select the check box and then click on the django admin action panel.
  4. Select import with parser app and click on go.
  5. Select your desired Excel file and submit.
  6. In the next step, you will be given the model's columns and the columns available in the Excel file.
  7. Map the columns to specify which column of the Excel file means which column of the Model and then submit.
  8. You will the shown the estimated data type validation errors in the next step. For example, your model field accept int value but your file contains string.
  9. If no validation errors are found, you will be asked to confirm upload.
  10. After confirmation, your data wil be imported in the desired model (in case of this example, Area model).

django-parser-app's People

Contributors

prantoamt avatar

Stargazers

 avatar  avatar  avatar  avatar

Watchers

 avatar  avatar

Forkers

dadafari

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.