Edit a model with all its ForeignKey related records using django inline formsets

178 views Asked by At

I have two models like below

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

class Book(models.Model):
    author = models.ForeignKey(Author)
    name = models.CharField(max_length=256)
    price = models.FloatField(max_length=256) 

So i am displaying the list of author and a link to edit the author record like below

{% for author in authors  %}
    <p><a href="{% url 'edit_author' author.id %}"></a></p>
{% endfor %} 

So if we want to edit only single Author class, then django UpdateView is simply enough to do so, but when a user try to edit an author, all the foreignkey records (Book records) related to this model should also be in Edit mode. I mean the clicked Author, and all the Book instances related to this Author with ForeignKey should also be in the edit mode exactly same in the Django Admin

I know that we can use django inline_formsets would be the choice, but i am really confused on how to implement it on my site(front end). So can anyone please let me know how to edit the author record along with its child records in a single page on our site ?

0

There are 0 answers