{"action":"closed","issue":{"url":"https://api.github.com/repos/tomchristie/django-rest-framework/issues/3522","labels_url":"https://api.github.com/repos/tomchristie/django-rest-framework/issues/3522/labels{/name}","comments_url":"https://api.github.com/repos/tomchristie/django-rest-framework/issues/3522/comments","events_url":"https://api.github.com/repos/tomchristie/django-rest-framework/issues/3522/events","html_url":"https://github.com/tomchristie/django-rest-framework/issues/3522","id":112284115,"number":3522,"title":"ModelSerializer cannot generate field for virtual field automatically","user":{"login":"lexdene","id":694227,"avatar_url":"https://avatars.githubusercontent.com/u/694227?v=3","gravatar_id":"","url":"https://api.github.com/users/lexdene","html_url":"https://github.com/lexdene","followers_url":"https://api.github.com/users/lexdene/followers","following_url":"https://api.github.com/users/lexdene/following{/other_user}","gists_url":"https://api.github.com/users/lexdene/gists{/gist_id}","starred_url":"https://api.github.com/users/lexdene/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/lexdene/subscriptions","organizations_url":"https://api.github.com/users/lexdene/orgs","repos_url":"https://api.github.com/users/lexdene/repos","events_url":"https://api.github.com/users/lexdene/events{/privacy}","received_events_url":"https://api.github.com/users/lexdene/received_events","type":"User","site_admin":false},"labels":[],"state":"closed","locked":false,"assignee":null,"milestone":null,"comments":1,"created_at":"2015-10-20T04:21:16Z","updated_at":"2015-10-20T06:22:24Z","closed_at":"2015-10-20T06:22:24Z","body":"In Django models, there are some fields called `virtual_fields`.\r\nModelSerializer cannot generate serializer fields for them automatically.\r\n\r\nexample code:\r\n\r\n```python\r\nfrom django.db import models\r\n\r\nfrom rest_framework import serializers\r\n\r\n\r\nclass Musician(models.Model):\r\n    first_name = models.CharField(max_length=50)\r\n    last_name = models.CharField(max_length=50)\r\n\r\n\r\nclass Album(models.Model):\r\n    artist = models.ForeignKey(Musician)\r\n    name = models.CharField(max_length=100)\r\n\r\n\r\nclass AlbumSerializer(serializers.ModelSerializer):\r\n    class Meta:\r\n        model = Album\r\n        fields = ('id', 'name', 'artist_id')\r\n\r\n\r\nalbum = Album.objects.last()\r\ndata = AlbumSerializer(album).data\r\n```\r\n\r\nthat will raise an error:\r\n\r\n    ImproperlyConfigured: Field name `artist_id` is not valid for model `Album`."}}