Get all fields in related model
See original GitHub issueIs there a way to get all the fields in a related model instead of having to explicitly follow individual relationships with the double underscore notation ('offer__provider'
)?
For example I have the following statement:
productapps = ProductApplication.objects.all().select_related('offer')
And I want to turn that queryset into a dataframe with all the fields from ProductApplication
and Offer
.
Issue Analytics
- State:
- Created 7 years ago
- Comments:7 (3 by maintainers)
Top Results From Across the Web
How to get all fields of related object Django - Stack Overflow
To formalize the answer, the instance is actually an instance of the model the form is based on. Thus, in your case, you...
Read more >QuerySet API reference | Django documentation
Annotates each object in the QuerySet with the provided list of query expressions. An expression may be a simple value, a reference to...
Read more >Making queries — Django 4.1.4 documentation
The simplest way to retrieve objects from a table is to get all of them. ... To span a relationship, use the field...
Read more >Get fields from related model - Odoo
Hi, if you need to show the car name and price together in a field, you have to define the name_get function for...
Read more >django get all fields from a model Code Example
django get all model fields ; 1. def get_model_fields(model): ; 2. return model._meta.fields ; 3. .
Read more >Top Related Medium Post
No results found
Top Related StackOverflow Question
No results found
Troubleshoot Live Code
Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start FreeTop Related Reddit Thread
No results found
Top Related Hackernoon Post
No results found
Top Related Tweet
No results found
Top Related Dev.to Post
No results found
Top Related Hashnode Post
No results found
Top GitHub Comments
This is how I solved it myself, in case it is useful to you at all.
Given class Parent, and class Child with FK to Parent:
Yes I benefit from open source 100%, and am happy to contribute wherever reasonable!
However, no I have not benefited from this project at all yet, because it did not do what I needed, which is: Get fields in related model. I provided my solution code above, “at no cost to you” as you say.
If I saw a simple way to integrate my solution code with this project, I may be willing to do so. But at the moment, its simpler for me to just use the 3 lines above. After briefly looking at this project’s source code, its not clear to me that the approach I took in my 3 lines would be directly helpful.
Of course I wish you the best with this project! Your goal is to connect two excellent open source frameworks which is awesome.