How can I prevent my Django Model from creating a "deferred attribute" for one of my model columns?

Viewed 25

Below is my model for "RunCounts"

 class RunCounts(models.Model):
    AccountUsername = models.TextField(blank = True)
    RunDate = models.DateTimeField(null=True)
    Report = models.TextField(blank = False)

When I later try to reference this in my views.py I cannot filter on the RunDate like I can all the other values in the model. Below is an example of me attempting to filter on it.

test = RunCounts.objects.filter(RunCounts.RunDate >= '2022-07-13')

returns the error: '>=' not supported between instances of 'DeferredAttribute' and 'str'

how can I either prevent django from making my RunDate column a 'DeferredAttribute' or be able to still use it in the filter?

1 Answers

You can .filter(…) [Django-doc] with:

RunCounts.objects.filter(RunDate__gt='2022-07-13')

Note: normally the name of the fields in a Django model are written in snake_case, not PascalCase, so it should be: run_date instead of RunDate.

Related