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

北慕城南 提交于 2021-02-19 23:10:36

问题


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(Is there Any easy way to implement this at file processing level).

Can Anyone help me how to implement this (Is there an SQLite parameter that I can mention 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/certain time/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, 'app/cta.html')

来源:https://stackoverflow.com/questions/65850277/how-to-set-daily-update-limit-for-django-modeldb

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!