This is an example of preview import django-import-export
outside admin.
Thanks alot to Andrés Meza-Escallón.
pip install -r requirements.txt
python manage.py migrate
python manage.py runserver
An example of preview import outside admin. (django-import-export)
This is an example of preview import django-import-export
outside admin.
Thanks alot to Andrés Meza-Escallón.
pip install -r requirements.txt
python manage.py migrate
python manage.py runserver
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.
A declarative, efficient, and flexible JavaScript library for building user interfaces.
🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.
TypeScript is a superset of JavaScript that compiles to clean JavaScript output.
An Open Source Machine Learning Framework for Everyone
The Web framework for perfectionists with deadlines.
A PHP framework for web artisans
Bring data to life with SVG, Canvas and HTML. 📊📈🎉
JavaScript (JS) is a lightweight interpreted programming language with first-class functions.
Some thing interesting about web. New door for the world.
A server is a program made to process requests and deliver data to clients.
Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.
Some thing interesting about visualization, use data art
Some thing interesting about game, make everyone happy.
We are working to build community through open source technology. NB: members must have two-factor auth.
Open source projects and samples from Microsoft.
Google ❤️ Open Source for everyone.
Alibaba Open Source for everyone
Data-Driven Documents codes.
China tencent open source team.