{"action":"created","issue":{"url":"https://api.github.com/repos/tomchristie/django-rest-framework/issues/2806","labels_url":"https://api.github.com/repos/tomchristie/django-rest-framework/issues/2806/labels{/name}","comments_url":"https://api.github.com/repos/tomchristie/django-rest-framework/issues/2806/comments","events_url":"https://api.github.com/repos/tomchristie/django-rest-framework/issues/2806/events","html_url":"https://github.com/tomchristie/django-rest-framework/issues/2806","id":67179630,"number":2806,"title":"Nested ModelSerializer are loading VERY lazy ","user":{"login":"bykof","id":5264141,"avatar_url":"https://avatars.githubusercontent.com/u/5264141?v=3","gravatar_id":"","url":"https://api.github.com/users/bykof","html_url":"https://github.com/bykof","followers_url":"https://api.github.com/users/bykof/followers","following_url":"https://api.github.com/users/bykof/following{/other_user}","gists_url":"https://api.github.com/users/bykof/gists{/gist_id}","starred_url":"https://api.github.com/users/bykof/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/bykof/subscriptions","organizations_url":"https://api.github.com/users/bykof/orgs","repos_url":"https://api.github.com/users/bykof/repos","events_url":"https://api.github.com/users/bykof/events{/privacy}","received_events_url":"https://api.github.com/users/bykof/received_events","type":"User","site_admin":false},"labels":[],"state":"closed","locked":false,"assignee":null,"milestone":null,"comments":1,"created_at":"2015-04-08T17:32:05Z","updated_at":"2015-04-08T18:11:11Z","closed_at":"2015-04-08T18:11:11Z","body":"Hi Tom,\r\nI use django-rest-framework for an internal application in my company. I really love drf and the awesome features it gaves me. But there's one thing which is disturbing me. I have a model with let's say a moderate count of related fields: \r\n```\r\nclass Order(models.Model, BookingModel):\r\n    ORDERED = 'ORDERED'\r\n    WAITING_FOR_DELIVERY = 'WAITING_FOR_DELIVERY'\r\n    DELIVERY_RECEIVED = 'DELIVERY_RECEIVED'\r\n    CREATED_INVENTORY_ITEM = 'CREATED_INVENTORY_ITEM'\r\n\r\n    STATUS_CHOICES = (\r\n        (ORDERED, _('Ordered')),\r\n        (WAITING_FOR_DELIVERY, _('Waiting for delivery')),\r\n        (DELIVERY_RECEIVED, _('Delivery received')),\r\n        (CREATED_INVENTORY_ITEM, _('Inventory item was created'))\r\n    )\r\n\r\n    bought_by = models.ForeignKey(User, related_name='bought_orders')\r\n    bought_on = models.DateTimeField(default=datetime.datetime.now, blank=True)\r\n    category = models.ForeignKey(OrderCategory, related_name='orders')\r\n    article = models.ForeignKey(Article, related_name='orders')\r\n    supplier = models.ForeignKey(Supplier, related_name='orders')\r\n    purpose = models.CharField(null=True, blank=True, max_length=255)\r\n    payment_method = models.ForeignKey(PaymentMethod, related_name='orders')\r\n    order_number = models.CharField(max_length=255)\r\n    delivery_received_on = models.DateTimeField(null=True, blank=True)\r\n    delivery_received_by = models.ForeignKey(User, null=True, blank=True, related_name='received_orders')\r\n    status = models.CharField(max_length=255, choices=STATUS_CHOICES, default=ORDERED)\r\n    tags = TaggableManager(blank=True)\r\n\r\n    class Meta:\r\n        verbose_name = _('Order')\r\n        verbose_name_plural = _('Orders')\r\n\r\n```\r\n\r\nand I use for the Model surely a ModelSerializer with a ModelViewSet. The only thing I set are the related fields, like this:\r\n```\r\nclass ReadOrderSerializer(ModelSerializer):\r\n    bought_by = UserSerializer()\r\n    category = OrderCategorySerializer()\r\n    article = ArticleSerializer()\r\n    supplier = SupplierSerializer()\r\n    payment_method = PaymentMethodSerializer()\r\n    tags = TagListSerializerField()\r\n\r\n    class Meta:\r\n        model = Order\r\n```\r\n\r\nNow we come to the problem :) \r\nThe problem is that I have to use pagination, because the loading is VERY slow. If I want to receive 25 orders it takes 1,12 secs. \r\n\r\nDo you have a setting to avoid the lazy load or can I change something in the code to do it faster? \r\n\r\nThank you very much\r\n\r\nBest Regards,\r\nMichael"},"comment":{"url":"https://api.github.com/repos/tomchristie/django-rest-framework/issues/comments/90992126","html_url":"https://github.com/tomchristie/django-rest-framework/issues/2806#issuecomment-90992126","issue_url":"https://api.github.com/repos/tomchristie/django-rest-framework/issues/2806","id":90992126,"user":{"login":"xordoquy","id":2340654,"avatar_url":"https://avatars.githubusercontent.com/u/2340654?v=3","gravatar_id":"","url":"https://api.github.com/users/xordoquy","html_url":"https://github.com/xordoquy","followers_url":"https://api.github.com/users/xordoquy/followers","following_url":"https://api.github.com/users/xordoquy/following{/other_user}","gists_url":"https://api.github.com/users/xordoquy/gists{/gist_id}","starred_url":"https://api.github.com/users/xordoquy/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/xordoquy/subscriptions","organizations_url":"https://api.github.com/users/xordoquy/orgs","repos_url":"https://api.github.com/users/xordoquy/repos","events_url":"https://api.github.com/users/xordoquy/events{/privacy}","received_events_url":"https://api.github.com/users/xordoquy/received_events","type":"User","site_admin":false},"created_at":"2015-04-08T18:11:10Z","updated_at":"2015-04-08T18:11:10Z","body":"Please don't use the issue tracker as a support forum.\r\nUsage questions should be asked on the mailing, IRC or StackOverflow.\r\nAs for your answer, DRF is built on top of Django. There are plenty blog posts explaining how to track the DB requests and how to optimize them. You likely didn't realize that spanning a relation creates a new DB request which makes the all page slow."}}