How to check manytomany connection of two objects?

class CustomUser(User): nick=models.CharField(max_length=20, blank=True, verbose_name=u'Ник') birthday=models.DateField(blank=True, null=True, verbose_name=u'День рождения') status=models.CharField(max_length=50, blank=True, verbose_name=u'Статус') creed=models.CharField(max_length=100, blank=True, verbose_name=u'Кредо') friends=models.ManyToManyField('self', blank=True, default=False) moderator=models.BooleanField(default=False) 
  • print (type (request.user)) gives <class 'django.utils.functional.SimpleLazyObject'>, it hardly gives me something. Elsewhere, the request.user attributes work everywhere like a CustomUser - LiGhT_WoLF

1 answer 1

 if first_object.secondobject_set.filter(pk= ).count(): … 
  • Here are the views: def another_profile (request, id): user1 = request.user user2 = CustomUser.objects.get (id = id) if user1.user2__set.filter (pk = .count (): friend = True gives the error 'CustomUser' object has no attribute 'user2__set'. how to fix? - LiGhT_WoLF
  • In general, if you correctly described the model, then the check will look like this: if user1.customuser_set.filter (pk = .count (): but I would like to take a look at this CustomUser ... - qnub
  • Well, how to make a check? - LiGhT_WoLF 1:53 pm
  • Clearly, how did you force django to use this model instead of django.contrib.auth.models.User? - qnub
  • Found a solution on the Internet, there is its auth_backends, where User is replaced by CustomUser - LiGhT_WoLF