I am assuming you have created_at and updated_at fields (these or similar) on the model.
You can write a query like below to get the count of no of rows updated that day using below code.
Remember to update the filters of the queryset as required e.g. user.
Reference :
https://docs.djangoproject.com/en/3.1/ref/models/querysets/#date
Regards,
Hi Jaimikp,
I have checked it but no luck. Can we make changes in the resource.py file?check the count and store that count into a variable and the next day the count value should get reset.I have checked before_import but not able to implement and also don't know if implementing this at resource.py level is good or at views.py logic code
Please find the below answer.--On Monday, January 25, 2021 at 9:23:50 PM UTC+5:30 jaimikp...@gmail.com wrote:Hi Shailesh,you can define the function with the use of DateTime module, which changes the value of the variable daily for the count.and for excel, you can get the number of lines in the file, and you can implement a validator as well.
https://stackoverflow.com/questions/13377793/is-it-possible-to-get-an-excel-documents-row-count-without-loading-the-entire-dOn Saturday, 23 January 2021 at 02:03:51 UTC+5:30 gabriela...@gmail.com wrote:Hi Sahilesh:Try with this:https://www.kite.com/python/answers/how-to-count-the-number-of-rows-in-a-pandas-dataframe-in-pythonEl viernes, 22 de enero de 2021 a las 14:39:35 UTC-3, shailesh...@gmail.com escribió:Thanks! but Can you elaborate more?howmany = mytable.count() = Here How it'll work and how to reset the value in 1 day. how I can use it in my code.import xlrd =I was trying something like this
def CTA_upload(request):
i = 1
count = (1,)
print('Counter value at starting :', len(count))
allcta = CTA.objecta.all()
allcta7 = len(tuple(allcta)) // 2
print('Tuple Check:', allcta7)
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, 'apple/uploadcts.html')
messages.info(request, 'Processing...')
imported_data = dataset.load(new_movie.read(), format='xls')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],
)if len(count) <= allcta7:
value.save()
i+= 1
count = append(i)
else:
messages.info(request, 'Sorry You have uploaded more data than specified limit...')
count.clear()
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.')print("Problem hai kuch to")
return render(request,'app/uploadcts.html')On Friday, January 22, 2021 at 10:45:54 PM UTC+5:30 gabriela...@gmail.com wrote:Previous, you can use:howmany = mytable.count()Also you can use xlrd library, for instance:On the other hand, the model has not contains records, it's only an structure definition of a tableGabriel Araya GarciaGMI - Desarrollo de Sistemas InformáticosEl vie, 22 ene 2021 a las 12:58, Shailesh Yadav (<shailesh...@gmail.com>) escribió:Hi I'm having one Django web app where My model A contains 1000 records and I want to set a daily update limit for example if users are updating that data by uploading a .xls file then it should count how many records updated and once it is more than 500 then the user should get an Error message.Can Anyone help me how to implement this (Is there a SQLite parameter where so that I can define value in settings.py)below is my upload code. (Here I have tried to store the count value and comparing it with half of the record but again how to reset it after 12 hrs?)
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, 'apple/uploadinfosys.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, 'apple/cta.html')--
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...@googlegroups.com.
To view this discussion on the web visit https://groups.google.com/d/msgid/django-users/95a6c5e9-ad98-4036-bcbb-109562a7df06n%40googlegroups.com.
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+unsubscribe@googlegroups.com.
To view this discussion on the web visit https://groups.google.com/d/msgid/django-users/c0d92522-590c-4ed7-bbb2-1a2a05868b37n%40googlegroups.com.
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+unsubscribe@googlegroups.com.
To view this discussion on the web visit https://groups.google.com/d/msgid/django-users/CAMKMUjsuGL2OKp-VpWPKB5yHF7UgVVHHxCgO3WZrt9Qjg5m5uA%40mail.gmail.com.
No comments:
Post a Comment