Possible to iterate over one query set but show the other? #8744
Unanswered
creyD
asked this question in
Question & Answer
Replies: 2 comments
-
This would easily work if I made the Serializer class the Config instead of the Alias. I always get a ImproperlyConfigured error message. Manually the following overwrite works: def to_representation(self, instance):
return {
'id': instance.id,
'config_param_1': instance.conf.config_param_1.name,
'config_param_2': instance.conf.config_param_2
} |
Beta Was this translation helpful? Give feedback.
0 replies
-
Also I got it to work now by explicitly adding the fields like this: |
Beta Was this translation helpful? Give feedback.
0 replies
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Uh oh!
There was an error while loading. Please reload this page.
-
We have a config object in our code and a simple table for config aliases (alias + config). I want to create a generic API using
ModelSerializers
for listing the following for each ALIAS:How I imagined the serialiser to look like working with the standard ModelViewSet is like this:
Then I would need to overwrite the method for getting the fields to take
alias.conf
fields. Trying a couple of ways (like below) I can't quite get it to work.Also tried overwriting
many_init
, with no success.TL;DR: I want the ListSerializer to iterate over the ALIAS model but really show the details for the CONFIG model plus the alias.id.
Beta Was this translation helpful? Give feedback.
All reactions