Hi Manas,
What about User model!? (Because of ForeignKey you declared)
This is where Friend.object.get() come from Friend model of current user.
On Sun, Jan 12, 2020, 11:50 manas srivastava
wrote:
>
>
>
> I have made a model to make friends using Django model. Now I am unable to
> get the friend id through the model. The model is as follows
>
> class Friend(models.Model):
>
> users = models.ManyToManyField(User) #following users
>
> current_user = models.ForeignKey(User, related_name='owner',
> null=True,on_delete=models.CASCADE) #followers
>
> @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)
>
>
>
> @classmethod
>
> def lose_friend(cls, current_user, new_friend):
>
> friend, created = cls.objects.get_or_create( 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
>
>
--
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+unsubscr...@googlegroups.com.
To view this discussion on the web visit
https://groups.google.com/d/msgid/django-users/CAP5HUWrJ-RYKnX0WS9saEEKJ%3DBU1VpedQn19h9X%3D4AWURQ66dQ%40mail.gmail.com.