1

Let's say I have the following model

class Plasmid (models.Model):
    name = models.CharField("name", max_length=255, unique=True, blank=False)
    map = models.FileField("plasmid map")
    formz_elements = models.ManyToManyField(FormZBaseElement)

and a function called get_plasmid_map_features, which takes a Plasmid.map, analyzes it, and returns a list of formz_elements.

I'd like to implement a custom button in the admin Plasmid form (e.g. "Click here to get plasmid features"), which would populate the formz_elements field WITHOUT having to hit Save(I can accomplish this upon form submission easily!), while leaving the values of all other fields untouched (i.e. I only want to change the formz_elements field).

Any suggestions?

Thanks in advance.

Nicola Zilio
  • 355
  • 6
  • 15
  • Can be done using JavaScript. You can write some JS code which will send the `plasmid map` file to the django backend and then fetch the results and populate `forms_elements`. If you know JS and AJAX, it's not that difficult. You'll also need to create a view which will accept `plasmid map` file and return the data in a response. – xyres Jul 24 '19 at 13:22
  • I understand that I need to use js JS and AJAX and create a view to analyze `plasmid_map`, it is nicely explained [here](https://stackoverflow.com/questions/17599035/django-how-can-i-call-a-view-function-from-template/19761466#19761466). What I don't understand is how to populate the initial value of `formz_elements` exclusively, which is a M2M field, while preserving any other field that a user may have entered already, but has not been yet saved to the db. – Nicola Zilio Jul 24 '19 at 16:54

0 Answers0