mirror of
https://github.com/encode/django-rest-framework.git
synced 2025-08-03 12:00:12 +03:00
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:
parent
052a20cd7b
commit
bd7925c181
|
@ -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):
|
||||||
|
|
Loading…
Reference in New Issue
Block a user