I have the following model:
class MyUser (user): # Some fields Contact = Model. Many people ("self", via = 'contact', symmetically = wrong, related_name = "contact_set") class contact (model. Model): user1 = models.ForeignKey (MyUser, related_name = " Contact_set1 ") User2 = models.ForeignKey (MyUser, related_name =" contact_set2 ") Confirmation = Model Booleanfield ()
and this view to create a contact
def Add_contact (request, user name = none): Username: try: user User.DoesNotExist: user = none if the user: contact = contact (user1 = MyUser.objects.get (pk) = Request.user.id), user2 = MyUser.objects.get (user name = username) User, confirm = false] contact.save () return to render_to_response ("accounts / add_contact.html", {'user': user,}): Returns HttpResponseRedirect ("/ home") DEF LES T_contacts (request, user name = Do not): If the user name: try: user = MyUser.objects.get (user name = username) except User.DoesNotExist: user = None else: user = MyUser.objects.get (pk = request.user id) If the user: contact = user.contacts.all () returns render_to_response ("accounts / list_contacts.html", {'contact': contact,}) Other: Returns HttpResponseRedirect ("/ home")
OK ... the code should be adequate verbose, so I will explain it briefly: social networking, users will be able to communicate with others their contact ("friend", "dos "Say, however you say it). If the user adds ABU, it is also in contact with the BA ...
The code works ... but there is only one way. If I'm logged in as User A and want to add User B to my contacts, then B will appear in my contacts list, but not in other ways. But I also want to show on B's contact list - it should not make any difference, who has added it? How do I manage it?
Docs say that "self" (in the form of a string) pass.
Also, see this.
Good luck. I hope you succeed in development.
Comments
Post a Comment