forked from AfthabEK/Entry-Exit-DL
-
Notifications
You must be signed in to change notification settings - Fork 0
/
clear_invalid.py
43 lines (31 loc) · 1.26 KB
/
clear_invalid.py
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
import os
import django
# Set up Django environment
os.environ.setdefault('DJANGO_SETTINGS_MODULE', 'entryexit.settings')
django.setup()
from enter.models import record # Replace 'your_app' with your actual Django app name
def delete_invalid_entries():
try:
# Get all records from the database
all_entries = record.objects.all()
# Filter invalid entries (roll number length not equal to 9)
invalid_entries = [entry for entry in all_entries if len(entry.rollno) != 9]
#find number of invalid entries
entry_count = len(invalid_entries)
# a confirmation message to delete the invalid entries
if entry_count > 0:
print(f"There are {entry_count} invalid entries.")
confirm = input("Do you want to delete them? (yes/no): ").lower()
if confirm == "yes":
for entry in invalid_entries:
print(f"Deleting invalid entry: {entry}")
entry.delete()
else:
print("Deletion canceled.")
else:
print("No invalid entries found.")
# Delete the invalid entries
except Exception as e:
print(f"An error occurred: {e}")
if __name__ == "__main__":
delete_invalid_entries()