имя приложения бэкэнд
Объект пользователя возвращает ошибку:
users = User.objects.filter(fb_userid=fb_user_id)
AttributeError: type object 'User' has no attribute 'objects'
models.py
from django.db import models
from django.contrib.auth.models import AbstractUser
class User(AbstractUser):
fb_userid = models.CharField(max_length=256)
avatar = models.ImageField(upload_to='avatars/', blank=True, null=True)
views.py
from backend.models import *
def fb_login(request):
# permission_classes = (permissions.AllowAny,)
if request.method == 'POST':
if 'fb_user_id' not in request.data:
return Response({'error':'missing fb_user_id'}, status=status.HTTP_404_NOT_FOUND)
fb_user_id = str(request.data['fb_user_id'])
users = User.objects.filter(fb_userid=fb_user_id)
if users.count() == 0:
user, created = User.objects.get_or_create(username=fb_user_id, email='fb@fb.net')
if created:
user.save()
else:
user = users[0]
token = Token.objects.get_or_create(user=user)[0]
# Likes
likeIds = []
likes = ImageLike.objects.filter(user_id=user.id)
for like in likes:
likeIds.append(like.image.id)
# Saved Places
savedIds = []
saved = SavedRestaurants.objects.filter(user_id=user.id)
for save in saved:
savedIds.append(save.restaurant.id)
jsonData = { 'token': token.key, 'saved': savedIds, 'likes': likeIds }
return Response(jsonData)
settings.py
AUTH_USER_MODEL = 'backend.User'
Объект пользователя возвращает ошибку:
users = User.objects.filter (fb_userid = fb_user_id) AttributeError: тип объекта «Пользователь» не имеет атрибута «объекты»