View Django-messages package notes

Source: Internet
Author: User

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.

  

  

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.