4
我做了一個自定義的用戶模型,通過參考tutorial,我這是怎麼序列化新的用戶模型:如何序列化自定義用戶模型DRF
Serializers.py
from django.conf import settings
User = settings.AUTH_USER_MODEL
class UserSerializer(serializers.ModelSerializer):
post = serializers.PrimaryKeyRelatedField(many=True, queryset=Listing.objects.all())
class Meta(object):
model = User
fields = ('username', 'email','post')
Views.py
from django.conf import settings
User = settings.AUTH_USER_MODEL
class UserList(generics.ListAPIView):
queryset = User.objects.all()
serializer_class = UserSerializer
但是當我試圖用這個序列化,我GE牛逼
'海峽' 對象有沒有屬性 '_meta'
我做了什麼錯?取而代之的
User = settings.AUTH_USER_MODEL
使用
是的,你是對的。但是對於django 1.8應該是'from django.contrib.auth import get_user_model' –
@ dev-jim修復了它。 – levi