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 8010559
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 4, 20262026-06-04T18:46:23+00:00 2026-06-04T18:46:23+00:00

Suppose I have a model of a comment in my project: class Comment(models.Model): text

  • 0

Suppose I have a model of a comment in my project:

class Comment(models.Model):
    text = models.TextField(max_length=500, blank=False)
    author = models.ForeignKey(User)

When serialized to JSON using django.core.serializers the author field comes out as:

"author": 1 // use_natural_keys = False
"author": ["someuser"] // use_natural_keys = True

Suppose I want to output the user’s first and last name as well? How would I go about that?

  • 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-04T18:46:26+00:00Added an answer on June 4, 2026 at 6:46 pm

    I assume you’re serializing your model in order to transmit it on wire (like in a http response).

    django.core.serializers is likely not the way you want to go. A quick approach would be to include a method on the model to return the dictionary you want to be serialized, then use simplejson.dumps to serialize it. E.g.:

    def to_json(self):
        return dict(
            author=[self.author.natural_key(), self.author.first_name, self.author.last_name],
            text=self.text,
        )
    

    then just call simplejson.dumps(comment.to_json()).

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

Sidebar

Related Questions

Suppose I have the following models: class User(models.Model): pass class A(models.Model): user = models.ForeignKey(User)
Suppose I have a model: class SomeModel(models.Model): id = models.AutoField(primary_key=True) a = models.CharField(max_length=10) b
Suppose I have my models set up already. class books(models.Model): title = models.CharField... ISBN
Suppose I have this model (not real code): class Message(models.Model): content = models.CharField(...) mentions
Hi Suppose I have a simple model class like this: class TestModel(models.Model): testkey =
Suppose I have class Foo(db.Model): bar = db.ReferenceProperty(Bar) foo = Foo.all().get() Is there a
Suppose I have an Orders table in my database and a corresponding model class
Suppose I have 2 models. The 2nd model has a one-to-one relationship with the
Suppose we have three models PATIENTS, NURSES, and their association model APPOINTMENTS. This week
Suppose I have the view models below. public class CustomerListViewModel { public IEnumerable<CustomerViewModel> Customers

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.