Give ForeignKeySource a custom manager

This change allows the tests to ensure that both forward and reverse
foreign key serialization works when the model has a custom manager.
This commit is contained in:
Rob Golding 2018-01-28 20:55:13 +00:00
parent 052a20cd7b
commit bd7925c181
No known key found for this signature in database
GPG Key ID: 8CC8F8E9495DE340

View File

@ -3,6 +3,8 @@ from __future__ import unicode_literals
import uuid import uuid
from django.db import models from django.db import models
from django.db.models.manager import BaseManager
from django.db.models.query import QuerySet
from django.utils.translation import ugettext_lazy as _ from django.utils.translation import ugettext_lazy as _
@ -45,12 +47,18 @@ class UUIDForeignKeyTarget(RESTFrameworkModel):
name = models.CharField(max_length=100) name = models.CharField(max_length=100)
class ForeignKeySourceManager(BaseManager.from_queryset(QuerySet)):
pass
class ForeignKeySource(RESTFrameworkModel): class ForeignKeySource(RESTFrameworkModel):
name = models.CharField(max_length=100) name = models.CharField(max_length=100)
target = models.ForeignKey(ForeignKeyTarget, related_name='sources', target = models.ForeignKey(ForeignKeyTarget, related_name='sources',
help_text='Target', verbose_name='Target', help_text='Target', verbose_name='Target',
on_delete=models.CASCADE) on_delete=models.CASCADE)
objects = ForeignKeySourceManager()
# Nullable ForeignKey # Nullable ForeignKey
class NullableForeignKeySource(RESTFrameworkModel): class NullableForeignKeySource(RESTFrameworkModel):