0

how to know when an instance of django model has been created inside sqlite? i tried many methods but i couldnt know or get when my db instance was created

from datetime import datetime, timedelta time_threshold = datetime.now() - timedelta(hours=4) results = x.objects.filter(created__lt=time_threshold)

i even tried this code but i got an error as below:

Traceback (most recent call last): File "", line 1, in File "C:\Users\momeir\Anaconda3\envs\myEnv\lib\site-packages\django\db\models\query.py", line 941, in filter return self._filter_or_exclude(False, args, kwargs) File "C:\Users\momeir\Anaconda3\envs\myEnv\lib\site-packages\django\db\models\query.py", line 961, in _filter_or_exclude clone._filter_or_exclude_inplace(negate, args, kwargs) File "C:\Users\momeir\Anaconda3\envs\myEnv\lib\site-packages\django\db\models\query.py", line 968, in _filter_or_exclude_inplace self._query.add_q(Q(*args, **kwargs)) File "C:\Users\momeir\Anaconda3\envs\myEnv\lib\site-packages\django\db\models\sql\query.py", line 1393, in add_q clause, _ = self._add_q(q_object, self.used_aliases) File "C:\Users\momeir\Anaconda3\envs\myEnv\lib\site-packages\django\db\models\sql\query.py", line 1412, in _add_q child_clause, needed_inner = self.build_filter( File "C:\Users\momeir\Anaconda3\envs\myEnv\lib\site-packages\django\db\models\sql\query.py", line 1286, in build_filter lookups, parts, reffed_expression = self.solve_lookup_type(arg) File "C:\Users\momeir\Anaconda3\envs\myEnv\lib\site-packages\django\db\models\sql\query.py", line 1112, in solve_lookup_type _, field, _, lookup_parts = self.names_to_path(lookup_splitted, self.get_meta()) File "C:\Users\momeir\Anaconda3\envs\myEnv\lib\site-packages\django\db\models\sql\query.py", line 1539, in names_to_path raise FieldError("Cannot resolve keyword '%s' into field. " django.core.exceptions.FieldError: Cannot resolve keyword 'created' into field. Choices are: contact_name, email_name, id, message, subject

1
  • Please provide enough code so others can better understand or reproduce the problem. Commented Feb 1, 2022 at 9:22

1 Answer 1

0

First question:
if you want to inspect your database, so it is easy
every database have both GUI and CLI usually, so sqlite also have a GUI that you can download it in sqlitebrowser.org

also your error say that your model dont have the created field so if it is not, give me more info.

qs = x.objects.filter(created__lt=time_threshold)

# to get number of objects only
n = qs.count()

# to get objects list
objs = qs.all()
Sign up to request clarification or add additional context in comments.

1 Comment

Thank you for the response, forget about the code I have shared , it won’t work since I have tried desperately the solution from other stackoverflow post . Simply I just want to query a queryset instance creation time and date , I can retrieve all data from queryset but there is no date time label when it was inserted to db so this is the issue

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.