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

The Archive Base Latest Questions

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

I have different models in my app, the main model having multiple instances of

  • 0

I have different models in my app, the main model having multiple instances of some other models.

models.py:

class Person(models.Model):
    ...

class Pet(models.Model):
    owner = models.ForeignKey(Person)
    ...

forms.py:

class PersonForm(forms.ModelForm):
    class Meta:
        model = Person


PetFormSet = inlineformset_factory(Person, Pet, extra = 1)

views.py:

def add_template(request):
    person_form = PersonForm(prefix = 'person_form')
    pet_form = PetFormSet(instance = Person(), prefix = 'pet_form')
    ... # check is_valid(), render when no POST data is present, etc.

The point is the addition works perfectly, storing each instance in the corresponding database table, etc. I use jquery.formset-1.2.js to manage the dynamical addition-deletion of forms in the “add.html”.

But I later want to edit the stored info through a view, i.e., load the data from the object I pass in the request, and render the formsets with the data obtained from the database (if there are 3 pets related to the person being editted, display 3 form instances of “Pet” with their value displayed).

I would like to also add new Pets and remove existing ones, as well as changing existing field values.

I have tried with querysets in the FormSet creation, but it doesn’t display anything.

Any idea how to ease this issue? Maybe using an app for an easier formset management?

Thank you

  • 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-18T08:45:15+00:00Added an answer on June 18, 2026 at 8:45 am

    I’m not sure if I understand your problem correctly. If you want to display all Pets that belong to the Person:

    def show_pets(request, person_id=None):
    person = get_object_or_404(Person.objects.select_related(), id=person_id)
    if request.method == 'POST':
       person_form = PersonForm(request.POST, instance=person)
       pet_formset = PetFormSet(request.POST, instance=person)
       # Rest of your code here
    else:
       person_form = PersonForm(instance=person)
       pet_formset = PetFormSet(instance=person)
    return render_to_response('your_template.html', {'person_form': person_form,
                                                            'pet_formset': pet_formset)})
    

    Then you just need to render both forms in your template and add add and delete functionality

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

Sidebar

Related Questions

So I have an app with a 2 different models, Comments and Replies, each
I currently have two different models: User and Project . The User model has
I have some models; Vocabularies (tags lists), Labels (tags) and different articles types. These
I have been developing some Django app and there's some duplicated code for different
In my PHP project I have two different models that have a function with
If I have two models that are very different, is it defeating the purpose
I have page where I use model which can have different types (depending by
I have a project which exposes object model to use by different types of
I have a Django app with classes for different things such as Post, Quote,
For my app, I have different signup entry points that validate things differently. So

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.