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

  • SEARCH
  • Home
  • 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 7815911
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 2, 20262026-06-02T05:40:37+00:00 2026-06-02T05:40:37+00:00

I have created a blog app which its model has an author field like

  • 0

I have created a blog app which its model has an author field like this:

author = models.ForeignKey(User)

I’m trying to modify default add view in django admin in order to get the added post take the logged first name user. How? This way:

def formfield_for_foreignkey(self, db_field, request, **kwargs):
    if db_field.name == 'author':
        kwargs['initial'] = request.user.id
        return db_field.formfield(**kwargs)

    return super(PostAdmin, self).formfield_for_foreignkey(db_field, request, **kwargs)

Well, in add view the select input which corresponds to author field shows the username. I want this select shows first_name + last_name field and not username field. And finally, when i success in this task, i want to hide this select. The logged user must not change the user who sends an entry to the blog.

I have been several hours working on this with no success. Help please!

Thanks a lot mates.

  • 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-02T05:40:38+00:00Added an answer on June 2, 2026 at 5:40 am

    One way to make the author foreign key field show User.first_name + User.last_name is to use a proxy model for the User in author:

    # your_app.models
    from django.contrib.auth.models import User
    
    
    class AuthorUser(User):
        class Meta:
            proxy = True
    
        def __unicode__(self):
            return '%s %s' % (self.first_name, self.last_name)
    
    
    class YourModel(models.Model):
        author = models.ForeignKey(AuthorUser)
    

    To make the field go away, you can simply mark it editable=False. Hope that helps you out.

    Edit:
    In Django 2.0, you will need an on_delete parameter in order to use ForeignKey.

    class YourModel(models.Model):
        author = models.ForeignKey(AuthorUser, on_delete=models.CASCADE)
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I have created a blog application using Ruby on Rails which includes the ability
I have a BizTalk 2006 app which has a sendport using MSMQ. I have
I have a simple blog app with the model Post. If I delete all
I'm new to cakephp and following this tutorial. http://book.cakephp.org/2.0/en/tutorials-and-examples/blog-auth-example/auth.html I have created the blog
I have created a simple blog application with Ruby on Rails. The applications consists
I have created a self-hosted wordpress blog and on my ftp server everything is
Not a question but i dont have a blog and i have just created
i have made a simple php contact form following this tutorial: http://www.catswhocode.com/blog/how-to-create-a-built-in-contact-form-for-your-wordpress-theme The big
I have a collection of entities with an any-association, like this: public class CreatedLog
I have been writing some code that creates a generic blog. Its features are

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.