0

I have the following code:

class Person(models.Model):
    name = models.CharField(max_length=32, verbose_name=_(u"Name"))
    surname = models.CharField(max_length=32, verbose_name=_(u"Surname"))
    address = models.CharField(max_length=32, verbose_name=_(u"Address"))

class Contract(models.Model):
    person        = models.ForeignKey(Person) #person hired
    project       = models.ForeignKey(Project, blank = True, null = True)
    starting_date = models.DateField(blank = True, null = True)
    ending_date   = models.DateField(blank = True, null = True)

Each person is shown with its own contract through an Inline.

I need to be able to modify a contract but without removing the contract I'm modifying, for the record of all contracts that a person has had. I mean, I'll have to make a copy of the contract I want to modify and then make the changes in that copy so at the end I'll have both contracts (the previous one and the modified version of that one).

I guess what I need is something like a link or button next to every row of the inline in order to go to the Contract admin page and modify a copy of that particular contract.

So far, I've seen some ways to make a copy but I don't know how to use them to do what I need.

Does anyone know how to go about it?

Community
  • 1
  • 1
loar
  • 1,505
  • 1
  • 15
  • 34
  • possible duplicate of [How do I clone a Django model instance object and save it to the database?](http://stackoverflow.com/questions/4733609/how-do-i-clone-a-django-model-instance-object-and-save-it-to-the-database) – Wtower Apr 23 '15 at 08:30
  • @Wtower I say in the penultimate line that I've seen that post but I need to get more info because what I want it's not just to copy but do it in the admin page inside the inline – loar Apr 23 '15 at 08:58
  • So you are looking for [`ModelAdmin.save_as`](https://docs.djangoproject.com/en/1.8/ref/contrib/admin/#django.contrib.admin.ModelAdmin.save_as) functionality inside `InlineModelAdmin` [AFAIK](https://docs.djangoproject.com/en/1.8/ref/contrib/admin/#inlinemodeladmin-options) it's not possible. – Todor Apr 23 '15 at 10:30
  • @Todor Quick thought: take the template of Contract and remove all buttons but the _Save as_ one. Create a link in the inline in order to go to that template. Could it work something like this? Problem: I can't find the save_as button in the template. – loar Apr 24 '15 at 08:53

0 Answers0