1, the role of select_related in Dajngo ORM Query
Select_related () method a one-time database associated objects are queried out into the object, re-query when you do not need to connect to the database, saving the number and time to query the database later. Mainly used for foreign key queries.
Blogobj = Blog.objects.filter (site=site). select_related (' user '). First ()
2. Customization of Blog theme
The CSS style of each module is fixed and then imported through the. css file, which can be set in the data. css file name in the template via link rel= "stylesheet" href= "/static/css/{{blogobj.theme}}.css "
3, from the database to filter the time, and the number (here stepped a hole!) Sweat! )
Using native SQL statements
First, you cannot use the GROUP by solution when using the MySQL statement (SQLite does not have this problem) Expression #1 of the SELECT list is not in the GROUP BY clause and contains Nonagg regated column ' UserInfo.: Solution:mysql> Set Global sql_mode= ' Strict_trans_tables,no_zero_in_date,no_zero_date, Error_for_division_by_zero,no_auto_create_user,no_engine_substitution ';mysql> set session sql_mode= ' STRICT_ Trans_tables,no_zero_in_date,no_zero_date,error_for_division_by_zero,no_auto_create_user,no_engine_ SUBSTITUTION '; second: the time format function in MySQL is date_format (CTime, "%%y-%%m") here two percent is to avoid the Django occurrence string parameter does error, if not add% will error: return "<%s :%s> "% (self.__class__.__name__, self.query) File" C:\Python36\lib\site-packages\django\db\models\sql\query.py " , line +, in __str__ return self.sql% Self.params_type (self.params) typeerror:not enough arguments for format String third uses the native statement: Select Nid, Count (nid) as Num, date_format (CTime, "%y-%m") as Create_time from Repository_article GR OUP by Date_format (CTime, "%%y-%%m"); The syntax for using SQLite is: ' Select Nid, Count (nid) as nUm,strftime ("%y-%m", Create_time) as CTime from Repository_article Group by strftime ("%y-%m", Create_time) ') here Date_ Format (CTime, "%y-%m") as Create_time must not be written date_format (CTime, "%y-%m") as CTime: Because itself CTime is a module, where if written CTime, The last query will be error: File "C:\Python36\lib\site-packages\pytz\__init__.py", line 222, in localize if dt.tzinfo are not None: Attributeerror: ' str ' object has no attribute ' Tzinfo '
Dajngo ORM Query select_related role, blog theme customization, from the database to filter time by month