I am uploading a .xls file and need to check the below condition before it saves to the model/database. requirement: 1.how to count the total no of rows and compare it with some value and if len(row)<=count(any variable) . 2. how to reset count variable in 1 day.
resource.py
```
class CTSResource(resources.ModelResource):
class meta:
Model=CTA
def before_import(self, dataset, using_transactions, dry_run, **kwargs):
--Logic code---
--Logic code---
```
I am trying to implement it at the file processing level in my views.py file as shown below.
def CTA_upload(request):
try:
if request.method == 'POST':
movie_resource = CTAResource()
##we will get data in movie_resources####
dataset = Dataset()
new_movie = request.FILES['file']
if not new_movie.name.endswith('xls'):
messages.info(request, 'Sorry Wrong File Format.Please Upload valid format')
return render(request, 'app/uploadinfo.html')
messages.info(request, 'Uploading Data Line by Line...')
imported_data = dataset.load(new_movie.read(), format='xls')
count = 1
for data in imported_data:
value = CTA(
data[0],
data[1],
data[2],
data[3],
data[4],
data[5],
data[6],
data[7],
data[8],
)
count = count + 1
value.save()
# messages.info(request, count)
# time.sleep(1)
messages.info(request, 'File Uploaded Successfully...')
except:
messages.info(request,'Same Email ID has been observed more than once.Except that other records has been added../nPlease Make sure Email field should be unique.')
return render(request,'app/cta.html')
```