On Thu, Dec 4, 2008 at 6:12 PM, Alan <[EMAIL PROTECTED]> wrote:

> Hi there!
> Although I have some experience in Python and Plone and have done Django
> tutorial, I am still not getting how to do a simple task I proposed myself:
> build a submitting page for a zip file.
>
> So I am looking at
> http://docs.djangoproject.com/en/dev/topics/http/file-uploads/
>
> It seems to have all I need, but I still don't know well how to connect the
> dots. So, it would be really great if I could put my hands in a example or,
> better, tutorial, of how to build such a page for submitting a file.
>
> The difficult I find is that when I was building webpages I used to think
> first the html code and then the rest, but with Django, I feel I have to
> think first models, but then I still lack how to link with view.
>

I think it makes sense to think first in terms of what you want to present
to the user for your task, which in Django would be a combination of a form
and template.  From there start thinking about what your view code needs to
do to manipulate the submitted form data to be saved in one or more model
instances.  What models you want to create rather depends on more than the
one simple task of submitting a zip file -- what sorts of things do you want
to do with the submitted zip files after they've been been submitted?

If the form for your task maps nicely to a single model then perhaps it
makes sense to use a ModelForm, but maybe not.  In some cases what should
logically be presented to the user doesn't map so nicely to what it makes
logical sense to keep in your database, and then it's best to give up on the
very easy ModelForm approach and write some custom forms and code that deals
with mapping from what is best for the user to deal with to what is best to
store in the DB.

To give a concrete example, I have a crossword puzzle database to which I
upload new published puzzles daily.  Models in the DB include Publishers,
Authors, Puzzles, Entries, and Clues.  There is no PuzzleFile model --
uploading a new puzzle file will involve creating a new Puzzle instance, may
involve creating a new Author instance, many new Entries instances, many new
Clues, etc.  Uploading and adding a puzzle is a two step process, the basic
upload form is very simple and doesn't involve any models. The file is
stashed in a staging area where it can be found and processed during the add
step, which is where actual DB models are created/updated.  In case it's of
any illustrative use, here's the basics of the upload code:
http://dpaste.com/96432/ -- form, view, and template.

Karen

--~--~---------~--~----~------------~-------~--~----~
You received this message because you are subscribed to the Google Groups 
"Django users" group.
To post to this group, send email to django-users@googlegroups.com
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