Django_messages is a Django app that provides registered users to send messages to each other. Recently, I have been studying its implementation mechanism. It is very easy to install and test. You can use it by importing packages, adding URLs and syncdb to generate databases.
I. Harvest 1:
Set auth_user_model = 'accounts. user' in setting ',
Then you can:
From Django. conf import settings
Auth_user_model = getattr (settings, 'auth _ user_model ', 'auth. user ')
Sender = models. foreignkey (auth_user_model, related_name = 'ent _ messages ')
Recipient = models. foreignkey (auth_user_model, related_name = 'stored ED _ messages ', blank = true, null = true)
The same database references two identical databases as foreign keys.
In addition, the reference database is written as a foreign key
Parent_msg = models. foreignkey ('self ', related_name = 'Next _ messages', null = true, blank = true)
Ii. Harvest 2:
Get_absolute_url
Address: http://mxjloveyou.blog.163.com/blog/static/1762546892012231105635330/
For example:
In the model
Def get_absolute_url (Self ):
Return ('message: community_activity_content ', [self. ID])
Get_absolute_url = models. permalink (get_absolute_url)
In the template;
<A href = "{% URL 'message: community_activity_content 'I. ID %}"> Replace
<A href = "{I. get_absolute_url}">
Hard encoding is successfully optimized.