Hi,

For a client, I've got the following (simplified) models:

class Document (models.Model):
  file = models.FileField()

class Publication (models.Model):
  title = models.CharField()
  ...
  documents = models.ManyToManyField(Document)


Publication can have several documents linked to it; my client wants
to be able to add a document in the same Django admin form as the
Publication; so instead of adding a document to the DB using the
(popup) Document form, and then selecting it from within the
Publication form, he wants an file upload box *in* the Publication add/
change admin form, so that when "Save" is clicked, before committing
the Publication to the DB, the file selected is converted to a
Document object, saved, and the ID of that Document is added to
Publication.documents, after which the Publication is saved.

I'm having a hard time thinking of a good 'clean' way to do this. I'm
basically adding two objects from within one (Publication) form. How
should I handle this?

I've got a custom form, with a custom widget for
Publication.documents, which adds a file upload box to the documents
field in the Publication form, but how do I handle the document upload
before the rest of publication's data is cleaned/validated?

Ideally, when the "Save" button is clicked, I'd like some jQuery to
check whether the file upload field is filled, and if so, upload the
file, show a progress bar indicating the upload's status. Once the
upload is finished, the file would be converted into a Document, and
it would somehow 'magically' (magically, because I don't really know
how this would work) return the new Document's ID, add it to the
<select> box, and the Publication form would happily get processed
without any extra checks.

Any ideas?

Henry A.

-- 
You received this message because you are subscribed to the Google Groups 
"Django users" group.
To post to this group, send email to [email protected].
To unsubscribe from this group, send email to 
[email protected].
For more options, visit this group at 
http://groups.google.com/group/django-users?hl=en.

Reply via email to