restframework 'tuple' object has no attribute '_meta'
Just wanted to add a potential case where such a thing might happen. In case you are using get_or_create
, keep in mind that this method returns a tuple, and not just the object.
As an example:
book = Book.objects.get_or_create(pk=123)
serializer = BookSerializer(book, request.data)
if serializer.is_valid():
serializer.save() # <-- Right here you would get the same error
The problem is fixed by unpacking the tuple:
book, created = Book.objects.get_or_create(pk=123)
# or this way if you do not need to know if it was created or not
book, _ = Book.objects.get_or_create(pk=123)
You are having the ,
after the name of BDetail
model in BDetailSerializer
serializer. Remove that and your code will work.
Suggestion: Inherit serializers.ModelSerializer
in your BDetailSerializer
serializer instead of serializers.HyperlinkedModelSerializer
i.e. :
class BDetailSerializer(serializers.ModelSerializer):
class Meta:
model = BDetail
fields = ('lat', 'lng')