question-mark
Stuck on an issue?

Lightrun Answers was designed to reduce the constant googling that comes with debugging 3rd party libraries. It collects links to all the places you might be looking at while hunting down a tough bug.

And, if you’re still stuck at the end, we’re happy to hop on a call to see how we can help out.

Calculated fields

See original GitHub issue

How do we access calculated fields? In a serializer I would do something like

class ArtworkSerializer(serializers.ModelSerializer):
    url = serializers.URLField(source='get_absolute_url')

    class Meta:
        model = Artwork
        fields = ('id', 'title', 'url')

I assume I need to specify this somehow in class ArtworkNode(DjangoNode): but I’ve been unable to discover how.

Issue Analytics

  • State:closed
  • Created 8 years ago
  • Comments:7 (3 by maintainers)

github_iconTop GitHub Comments

3reactions
syrusakbarycommented, Feb 2, 2016

Sure. You can do it using arguments.

class Query(graphene.ObjectType):
    artwork = graphene.Field(ArtworkNode, slug=graphene.String())

    def resolve_artwork(self, args, info):
        return Artwork.get_by_slug(args.get('slug', None))

Then you can query it with the following query:

{
  artwork(slug:"my_slug") {
    id
    title
  }
}

Hope it helps!

1reaction
syrusakbarycommented, Feb 2, 2016

Great! However I’m going to add the source option to fields! It makes it much more pleasant to develop!

So you can do something like

class ArtworkNode(DjangoNode):
    url = graphene.String(source='get_absolute_url')

    class Meta:
        model = Artwork
        filter_fields = ['id', 'title']
Read more comments on GitHub >

github_iconTop Results From Across the Web

How to Create Excel Pivot Table Calculated Field Examples
In a pivot table, you can create a new field that performs a calculation on the sum of other pivot fields, using your...
Read more >
Calculate values in a PivotTable
Click the PivotTable. · On the Analyze tab, in the Calculations group, click Fields, Items, & Sets, and then click Calculated Field. ·...
Read more >
About calculated fields - Looker Studio Help
A calculated field is a formula that performs some action on one or more other fields in your data source. Calculated fields can...
Read more >
Create a Calculated Field in Excel Pivot Table - YouTube
In an Excel pivot table, you can create your own formulas, by using a calculated field.In this video, see how to create a...
Read more >
Create a Simple Calculated Field
In a worksheet in Tableau, select Analysis > Create Calculated Field. In the Calculation Editor that opens, give the calculated field a name....
Read more >

github_iconTop Related Medium Post

No results found

github_iconTop Related StackOverflow Question

No results found

github_iconTroubleshoot Live Code

Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free

github_iconTop Related Reddit Thread

No results found

github_iconTop Related Hackernoon Post

No results found

github_iconTop Related Tweet

No results found

github_iconTop Related Dev.to Post

No results found

github_iconTop Related Hashnode Post

No results found