Hi, I am using the django_import_export package but i am not been able to
import files, the tables are related. Please find the attached
files(models, resources and admin) for your reference.
Please help me
--
You received this message because you are subscribed to the Google Groups
"Django users" group.
To unsubscribe from this group and stop receiving emails from it, send an email
to django-users+unsubscr...@googlegroups.com.
To view this discussion on the web visit
https://groups.google.com/d/msgid/django-users/CALYpPT-j0jNMZYm7POFfW94fjjSkATEn_ZAYYn6kZx6Wyc3AfQ%40mail.gmail.com.
from django.db import models
from django.utils import timezone
from django.conf import settings
import decimal
from apps.product.models import *
# Permit Information Analysis
class Info(models.Model):
O_PORT = [
('Overland', 'Overland'),
('Ghana', 'Ghana'),
('By Air', 'By Air'),
('By Road', 'By Road'),
('Takoradi', 'Takoradi'),
('Tema', 'Tema'),
]
PAYMENT_TYPE = [
('Cash Against Document', 'Cash Against Document'),
('Bank Draft', 'Bank Draft'),
('Cash Against Document', 'Cash Against Document'),
('Letter of Credit', 'Letter of Credit'),
('Wire Transfer', 'Wire Transfer'),
('PrePaid', 'PrePaid'),
]
exporter = models.CharField(max_length=150)
buyer = models.CharField(max_length=150)
vessel = models.CharField(max_length=150)
date_of_transaction = models.DateField(default=timezone.now, verbose_name="Transaction Date")
originating_port = models.CharField(choices=O_PORT, max_length=8, default="Ghana")
city_destination = models.CharField(max_length=150, verbose_name="City of Destination")
country_destination = models.ForeignKey(Country, on_delete=models.CASCADE, verbose_name="Country of Destination")
contract_number = models.CharField(max_length=150, verbose_name="Contract Number")
a2_form = models.CharField(max_length=50, blank=True, null=True)
payment_type = models.CharField(max_length=100)
negotiating_bank = models.ForeignKey(Bank, on_delete=models.CASCADE)
container_or_vehicle = models.CharField(max_length=50)
driver_name = models.CharField(max_length=150, blank=True)
# records on user
added_by = models.ForeignKey(settings.AUTH_USER_MODEL, on_delete=models.SET_NULL, null=True, blank=True, editable=False, verbose_name="Added By")
updated_by = models.CharField(max_length=50, default='Admin', null=True, blank=True)
date_added = models.DateTimeField(auto_now_add=True)
permit_NUM = models.CharField(max_length=30, unique=True, verbose_name="Permit Number")
class Meta:
verbose_name = "Capture Permit Info"
verbose_name_plural = verbose_name
def __str__(self):
return self.exporter
# Permit
class Permit(models.Model):
CONVERSION = [
('1.', '1.'),
('0.0006', '0.0006'),
('0.0007', '0.0007'),
('0.0010', '0.0010'),
('0.0015', '0.0015'),
]
UNITS = [
('m2', 'm2'),
('m3', 'm3'),
]
CURRENCY = [
('USD', 'USD'),
('GHS', 'GHS'),
('CFA', 'CFA'),
('Euro', 'Euro'),
]
product = models.ForeignKey(Product, on_delete=models.CASCADE)
specie = models.ForeignKey(Specie, on_delete=models.CASCADE)
grade = models.ForeignKey(Grade, on_delete=models.CASCADE)
info = models.ForeignKey(Info, on_delete=models.CASCADE)
# volume
volume = models.DecimalField(max_digits=19, decimal_places=3)
conversion_factor = models.CharField(choices=CONVERSION, max_length=8)
units = models.CharField(choices=UNITS, max_length=5, default='m3')
unit_price = models.DecimalField(max_digits=19, decimal_places=2)
currency = models.CharField(max_length=15)
ex_rate = models.DecimalField(max_digits=19, decimal_places=4, verbose_name='Exchange Rate')
def __str__(self):
return self.info.exporter
@property
def my_value(self):
val = self.volume * self.unit_price
val = round(val, 2)
return val
@property
def derived_volume(self):
dv = self.volume * decimal.Decimal(self.conversion_factor)
dv = round(dv, 3)
return dv
@property
def euro_value(self):
ev = self.volume * self.unit_price * self.ex_rate
ev = round(ev, 2)
return ev
from import_export import resources
from apps.permit.models import Permit, Info
from apps.product.models import *
from import_export.fields import Field
from import_export.widgets import ForeignKeyWidget
import decimal
# Resource for import nd export
class PermitResource(resources.ModelResource):
info__exporter = Field(column_name='Exporter', attribute='info',
widget=ForeignKeyWidget(Info, 'exporter'))
product__name = Field(column_name='Product', attribute='prod