Re: Passing parent with multiple childs from View to HTML

2009-09-27 Thread Jay

In Django template, you can make methed call. So you can pass the
auther object to the template, then
  {% for book in auther.books.all %}

{% for section in book.sections.all %}
  
{% end for %}
  {% endfor %}

The ordering is using the definition in the Model Meta class.
auther.books and book.sections is my assumption for your FK related
names.

If you want to change the ordering, maybe a template tag is more
suitable for your purpose.

And about Form, I'm not clear what you want? A whole page with forms
for authors, books and sections? If so, you can have a look at
formset, specially the inlineformset. (http://docs.djangoproject.com/
en/dev/topics/forms/modelforms/#inline-formsets) If you just want to
get a simple form for inline editing in the author-book-section view
page, using js to generate it is my only choice

On Sep 27, 1:39 am, PlanetUnknown  wrote:
> I have been studying the modalforms & inline formsets but am not able
> to wrap my head around my composite objects, and want to see how
> things are done in django world -
>
> I have this hierarchical model
> "Author" has many "Books"
>   Each "Book" has 4 Sections -> Section-01, Section-02, Section-03 &
> Section-04
>     Each "Section" has number of attributes.
>
> I want to show all books on its own line
> If a book is clicked, I'll expand a hidden DIV, which will show the 4
> sections of that book.
> Like so -
> Book-1 | Short Description of book (when clicked, shows the below
> section)
> Section-01 | Section-02 | Section-04 | Section-04 |
> Book-2 | Short Description of book (when clicked, shows the below
> section)
> Section-01 | Section-02 | Section-04 |...
> ...
> ..
> .
>
> I have all the HTML code figured out, using jquery to show/hide Divs.
>
> Question - I'm confused as to how I can pass all this data from the
> view to the HTML page and then render so that when user edits
> something, things are passed back, in the form of Forms.
>
> But is there a way to pass this whole composite object - Author+Books
> +AllSectionsInBook in one go.
>
> Would be great if you could point me in a direction or how you solved
> this composition problem.
> Thanks a lot in advance !
--~--~-~--~~~---~--~~
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 
django-users+unsubscr...@googlegroups.com
For more options, visit this group at 
http://groups.google.com/group/django-users?hl=en
-~--~~~~--~~--~--~---



Passing parent with multiple childs from View to HTML

2009-09-26 Thread PlanetUnknown

I have been studying the modalforms & inline formsets but am not able
to wrap my head around my composite objects, and want to see how
things are done in django world -

I have this hierarchical model
"Author" has many "Books"
  Each "Book" has 4 Sections -> Section-01, Section-02, Section-03 &
Section-04
Each "Section" has number of attributes.

I want to show all books on its own line
If a book is clicked, I'll expand a hidden DIV, which will show the 4
sections of that book.
Like so -
Book-1 | Short Description of book (when clicked, shows the below
section)
Section-01 | Section-02 | Section-04 | Section-04 |
Book-2 | Short Description of book (when clicked, shows the below
section)
Section-01 | Section-02 | Section-04 |...
...
..
.

I have all the HTML code figured out, using jquery to show/hide Divs.

Question - I'm confused as to how I can pass all this data from the
view to the HTML page and then render so that when user edits
something, things are passed back, in the form of Forms.

But is there a way to pass this whole composite object - Author+Books
+AllSectionsInBook in one go.

Would be great if you could point me in a direction or how you solved
this composition problem.
Thanks a lot in advance !
--~--~-~--~~~---~--~~
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 
django-users+unsubscr...@googlegroups.com
For more options, visit this group at 
http://groups.google.com/group/django-users?hl=en
-~--~~~~--~~--~--~---