Sunday, December 29, 2019

Re: How to read Objects from ManyToMany Relation class in django

Hi,

Check url.py with typo error at closed parenthesic.

On Sun, Dec 29, 2019, 20:35 manas srivastava <mastermanas805@gmail.com> wrote:

I have made a class called friend where i want to connect users as followers. Here From this class i am unable to read the users those are following another user. For Eg if 'a' user fllows 'b' user. Then i want to get the names of user that followed b from the user id of b and display them as followers of a. This class is also not storing the userid of the following user and followed user. I am new to many to many relation field. Kindly help.

Code in Models.py

class Friend(models.Model):        users = models.ManyToManyField(User)        current_user = models.ForeignKey(User, related_name='follower', null=True,on_delete=models.CASCADE)        @classmethod        def make_friend(cls, current_user, new_friend):            friend, created = cls.objects.get_or_create(                current_user = current_user            )            friend.users.add(new_friend)  

Its function in views.py is

def change_friends(request, operation, pk):        friend = User.objects.get(pk=pk)        if<span class="pln" style="border-bottom-color: currentColor; border-bottom-style: none; border-bottom-width: 0px; border-image-outset: 0; border-image-repeat: stretch; border-image-slice: 100%; border-image-source: none; border-image-width: 1; border-left-color: currentColor; border-left-style: none; border-left-width: 0px; border-right-color: currentColor; border-right-style: none; border-right-width: 0px; border-top-color: currentColor; border-top-style: none; border-top-width: 0px; box-sizing: inherit; color: rgb(48, 51, 54); font-family: inherit; font-size: 100%; font-size-adjust: none; font-stretch: 

--
You received this message because you are subscribed to the Google Groups "Django users" group.
To unsubscribe from this group and stop receiving emails from it, send an email to django-users+unsubscribe@googlegroups.com.
To view this discussion on the web visit https://groups.google.com/d/msgid/django-users/CAP5HUWo%3D6Ca5Zc_QQ1snbXx0CyP6VaR2MdBnQNLgcT8hqmXMEQ%40mail.gmail.com.

No comments:

Post a Comment