While testing my features in a Django Rest framework App, I need to get an object, let's call it Foo
and this object has some nested relationships. I can get it by my making a request with the APIClient
as such :
class FooTest(TestCase):
def setUp(self):
self.client = APIClient()
def test_foo_feature(self):
foo_id = generator.generateFoo().id
foo = self.client.get(reverse('foo-detail', args=[foo_id])).data
I was wondering if I could call directly my FooSerializer
in a certain way to get my Foo
object with the nested relationships, instead of passing by the view with the help of the APIClient
because simply calling Foo.objects.get(id=foo_id)
doesn't return the nested relationships.
question from:
https://stackoverflow.com/questions/66051661/django-rf-how-to-get-a-django-model-with-nested-relationship 与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…