Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- views.py
- def post(self, request):
- """POST requests"""
- if self.request.POST and self.request.FILES:
- print('picking file ---------')
- csvf = self.request.FILES['file[]']
- print('Found file --',csvf, 'file---------')
- title = self.request.POST['title']
- user = request.user
- product = Product.objects.create(title=title, file=csvf)
- if not csvf:
- raise ValueError('Kindly select a file for upload')
- try:
- with transaction.atomic():
- product.save()
- if user and product:
- print('processing...... products')
- async_task('apps.payment.tasks.process_products',
- user, product, csvf)
- tasks.py
- def process_products(user, product, file):
- if user and product:
- reader = csv.reader(file)
- n = next(reader, None)
- print(n)
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement