Hi Shailesh,

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.


from django.utils import timezone

current_date = timezone.now().date()

edited_count = Model.objects.filter(updated_at__date=current_date).count()


Reference :
https://docs.djangoproject.com/en/3.1/ref/models/querysets/#date

I hope it helps you.

Cheers!


Regards,
Chetan Ganji
+91-900-483-4183
ganji.che...@gmail.com
http://ryucoder.in


On Fri, Feb 5, 2021 at 7:12 AM Shailesh Yadav <shaileshyadav7...@gmail.com>
wrote:

> 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.
>
> https://stackoverflow.com/questions/66042509/how-to-check-perform-field-validation-in-resource-py
>
>
> 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.
>>
>> 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
>>>>>> <https://groups.google.com/d/msgid/django-users/95a6c5e9-ad98-4036-bcbb-109562a7df06n%40googlegroups.com?utm_medium=email&utm_source=footer>
>>>>>> .
>>>>>>
>>>>> --
> 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/c0d92522-590c-4ed7-bbb2-1a2a05868b37n%40googlegroups.com
> <https://groups.google.com/d/msgid/django-users/c0d92522-590c-4ed7-bbb2-1a2a05868b37n%40googlegroups.com?utm_medium=email&utm_source=footer>
> .
>

-- 
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/CAMKMUjsuGL2OKp-VpWPKB5yHF7UgVVHHxCgO3WZrt9Qjg5m5uA%40mail.gmail.com.

Reply via email to