Monday, January 25, 2021

Re: How to set daily update limit for django model(db)?

Hi Shailesh,

you can define the function with the use of DateTime module, which changes the value of the variable daily for the count.
https://stackoverflow.com/questions/52305294/changing-a-variable-based-on-current-time-of-day

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-d


On 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-python

El 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:
import xlrd
 
#open excel file
documento = xlrd.open_workbook("ejemplo.xls")
 
#We can save each one of the spreadsheet separately
libros = documento.sheet_by_index(0)
peliculas = documento.sheet_by_index(1)
  
On the other hand, the model has not contains records, it's only an structure definition of a table


Gabriel Araya Garcia
GMI - Desarrollo de Sistemas Informáticos




El 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/948eae67-5754-4ddf-8d4c-9ada5d095a95n%40googlegroups.com.

No comments:

Post a Comment