Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • Home
  • SEARCH
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 8844537
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 14, 20262026-06-14T11:30:45+00:00 2026-06-14T11:30:45+00:00

In Django, every model has a pseudo attribute pk , that points to the

  • 0

In Django, every model has a pseudo attribute pk, that points to the field that is declared as primary key.

class TestModel(models.Model):
    payload = models.Charfield(max_length=200)

In this model, the pk attribute would point to the implicit id field, that is generated if no field is declared to be the primary.

class CustomPK(models.Model)
    primary = models.CharField(max_length=100, primary=True)
    payload = models.Charfield(max_length=200)

In this model, the pk attribute would point to the explicit defined primary key field primary

So my question is, how can I get the name of the field, that is the primary key?

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-06-14T11:30:49+00:00Added an answer on June 14, 2026 at 11:30 am

    You will also have an attribute “name” on the pk-attribute. This seems to hold the name of the Field.

    CustomPK._meta.pk.name
    

    In my case I get the value “id” as result (like it should). 🙂

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

Every Django model has a default primary-key id created automatically. I want the model
I have a model MyModel that has a field expiration_datetime. Every time a user
I have a client that has an app built with django. On every page
I have 2 models in my Django code: class ModelA(models.Model): name = models.CharField(max_length=255) description
I have a model (lets call it Entity) that has an attribute (Attribute) that
In a Django UserProfile model, I am trying to do the following: class UserProfile(models.Model):
In my models.py: from django.db import models from core import tasks class Image(models.Model): image
I have two models in Django: groups and entries. Groups has a many-to-many field
Let's assume that I have following models: class ScoutBook(models.Model): troop = models.ForeignKey('Dictionary', limit_choices_to={'type' :
I am writing a Django application that has a model for People, and I

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.