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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 26, 20262026-05-26T19:51:17+00:00 2026-05-26T19:51:17+00:00

Standard example: class Author(models.Model): name = models.CharField(max_length=100) class Book(models.Model): title = models.CharField(max_length=100) author =

  • 0

Standard example:

class Author(models.Model):
  name = models.CharField(max_length=100)

class Book(models.Model):
  title = models.CharField(max_length=100)
  author = models.ForeignKey(Author)
  #... Many other fields ...

I’d like to edit the Books from the Author change page.
I tried with InlineModelAdmin but since Book has many fields, it’s not easy to edit.
That’s why I tried to put links towards the children on the author/change template.

<ul>
  <li><a href="{% url admin:content_scribpart_add %}">Add a Book</a></li>
{% for book in original.book_set.all %}
  <li><a href="{% url admin:myapp_book_change book.id %}">Edit {{ book }}</a></li>
{% endfor %}
</ul>

But there are several questions

  • How can I prepopulate the related Author id in the Book form
  • How can I make the Save button to go back to the related Author
  • Am I on right track ?
  • 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-05-26T19:51:18+00:00Added an answer on May 26, 2026 at 7:51 pm

    Yes, sure.

    1. Append author primary key as GET parameter to your url:

      <ul>
        <li><a href="{% url admin:content_scribpart_add %}?author={{ object_id }}">Add a Book</a></li>
      {% for book in original.book_set.all %}
        <li><a href="{% url admin:myapp_book_change book.id %}?author={{ object_id }}">Edit {{ book }}</a></li>
      {% endfor %}
      </ul>
      
    2. Modify the corresponding ModealAdmin for book, override response_add() and response_change(). Note that we also override formfield_for_forein_key in order to pre-populate author field:

      from django.http import HttpResponseRedirect
      from django.core.urlresolvers import reverse
      
      class BookAdmin(admin.ModelAdmin):
      
          def formfield_for_foreignkey(self, db_field, request, **kwargs):
              if db_field.name == "author":                    
                  try:
                      author_pk = int(request.GET.get('author', ''),) 
                  except ValueError:           
                      pass
                  else:
                      kwargs["initial"] = Author.objects.get(pk=author_pk)
      
              return super(BookAdmin, self).formfield_for_foreignkey(db_field, request, **kwargs)
      
          def response_add(self, request, obj, post_url_continue=None):
              return HttpResponseRedirect(reverse('admin:myapp_author_change', args=(obj.author.pk,))
              )
      
          def response_change(self, request, obj, post_url_continue=None):
              return HttpResponseRedirect(reverse('admin:myapp_author_change', args=(obj.author.pk,))
              )
      
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

Lets take the standard example class Author(models.Model): name = models.CharField(max_length=100) class Book(models.Model): title =
Lets take the standard example class Author(models.Model): name = models.CharField(max_length=100) class Book(models.Model): title =
For example, the standard division symbol '/' rounds to zero: >>> 4 / 100
taking a standard browser as example, there is the Window class instantiated as window
Normally my URLs look like the standard: www.example.com/controller/action Now I want to setup my
If for example I should not use standard library functions like printf() , putchar()
I used to have my permalinks to standard format, something like http://example.com/?page_id=2 . Now
The standard model has been that OpenGL is for professional apps (CAD) and Direct3D
On my server, I'm using the standard example for Python (with an extra Hello
I have a standard windows server that inherits from the ServiceBase class. On the

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.