Home > other >  Django ORM F year of filter expressions
Django ORM F year of filter expressions

Time:09-17

The class author (models. Model) :
Author_time=models. DateTimeField ()


The class book (models. Model) :
Author_info=models. ForeignKey (author, on_delete=models. The CASCADE)
Book_time=models. DateTimeField ()


Test=book. Objects. The filter (book_time__year=F (' author_info__author_time__year))
After adding data in the database to query book_time and author_time book list are of the same year, but the use of filter statement query result has been a 0
If not used, what's the problem?

CodePudding user response:

From efficiency for, if you need such a comparison, the book the author respectively increase in a field, to compare, a higher efficiency and easy to write
  • Related