Giter VIP home page Giter VIP logo

django-import-preview-example's Introduction

Django Import Outside Admin Example

This is an example of preview import django-import-export outside admin. Thanks alot to Andrés Meza-Escallón.

How to install

pip install -r requirements.txt
python manage.py migrate
python manage.py runserver

Screenshot

Import

Import

Import Preview

Import Preview

django-import-preview-example's People

Contributors

smalldale avatar

Stargazers

 avatar

Watchers

 avatar

Forkers

5no0p nineteenss

django-import-preview-example's Issues

Getting: 'ImportProductsView' object has no attribute 'get_import_resource_class'

Hello! Having an issue here. Getting an object has no attribute 'get_import_resource_class'

Recreated the files hierarchy and basically just made these two classes in views.py:

class ImportProductsView(ImportView):
   
  import_template_name = 'dashboard/import_export/import.html'
  resource_class = ProductResource
  model = Product

and

class ConfirmImportProducts(ConfirmImportView):
    
  import_template_name = 'dashboard/import_export/import.html'
  resource_class = ProductResource
  model = Product
  success_url = reverse_lazy('products')

And added in urls.py:

path("dashboard/products/confirm/", ConfirmImportProducts.as_view(), name='confirm_import_products'),
path("dashboard/products/import/", ImportProductsView.as_view(), name='import_products'),

ProductResource in resources.py:

from import_export import resources
from import_export.fields import Field
from import_export.widgets import ForeignKeyWidget, NumberWidget, IntegerWidget

from .models import Product, Category, SubCategory
       

class ProductResource(resources.ModelResource):
    
  id = Field(
      attribute='id', 
      column_name='id'
  )   
   
  parent = Field(
      attribute='parent', 
      column_name='parent', 
      widget=ForeignKeyWidget(
          Category,
          'title'
      )
  ) 
  
  category = Field(
      attribute='category', 
      column_name='category',
      widget=ForeignKeyWidget(
          SubCategory,
          'title'
      )
  )
  
  title = Field(
      attribute='title', 
      column_name='title'
  )
  
  vendor_code = Field(
      attribute='vendor_code', 
      column_name='vendor_code'
  )
  
  price = Field(
      attribute='price', 
      column_name='price',
      widget=IntegerWidget()
  )
  
  unit = Field(
      attribute='get_unit_display', 
      column_name='unit'
  )
  
  stock_amount = Field(
      attribute='stock_amount', 
      column_name='stock_amount',
      widget=NumberWidget()
  )
  
  description = Field(
      attribute='description', 
      column_name='description'
  )
  
  image = Field(
      attribute='image', 
      column_name='image'
  )
  
  class Meta:
      model = Product
      
      skip_unchanged = True
      use_bulk = False
      
      import_id_fields = ('id',)
  
      fields = (
          'id',
          'parent',
          'category',
          'title',
          'vendor_code',
          'price',
          'unit',
          'stock_amount',
          'description',
          'image'
      )
  
  def get_queryset(self):
      return self._meta.model.objects.order_by('id')

The main goal, is of course, creating the 'Preview'. And with this error it's mostly impossible to do that. Not sure what am i doing wrong here.

Just to mention: I can't blame resources.py because it works if i make it work without 'Preview' stage, just as a straight import by a different code using function based view.

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.