Access Django Model primary key
See original GitHub issueHi,
I would like to do something like this:
allIngredients {
edges {
node {
id
pk
name
}
}
}
where the result would be something like this:
{
"id": "Q29tcGFueU5vZGU6MQ==",
"pk": 42,
"name": "carrots"
}
Is this possible? How could it be achieved?
Perhaps relatedly, how could I expose model properties?
Thanks!
Issue Analytics
- State:
- Created 7 years ago
- Comments:7 (5 by maintainers)
Top Results From Across the Web
Models | Django documentation
Models ¶. A model is the single, definitive source of information about your data. It contains the essential fields and behaviors of the...
Read more >Get name of primary field of Django model
In Django, every model has a pseudo attribute pk , that points to the field that is declared as primary key. class TestModel(models....
Read more >primary_key - Django Built-in Field Validation
Built-in Field Validations in Django models are the default validations that come predefined to all Django fields. Every field comes in with ...
Read more >notes/models.md at master · pshrmn/notes
By default, Django adds an id field to each model, which is used as the primary key for that model. You can create...
Read more >Model instance reference — Django 4.1.4 documentation
Regardless of whether you define a primary key field yourself, or let Django supply one for you, each model will have a property...
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
Can I just clarify - so
id
retrieves the primary key, unless theNode
interface is used in which case it’s the relay node id?The
id
retrieves automatically the Primary Key in the Django Model instance by default, as @bcb pointed.You can expose model properties by creating a field for the property. For example, if your Model looks something like: