On Sun, 15 Dec 2013 01:20:17 -0800 (PST)
giuliano.bertole...@gmail.com wrote:

>  
> Hello,
>  
> I'm wondering how you would you organize the url layout in a following 
> scenario
>  
> Suppose I've a table of Authors and for each author a list of books.
> A book can have only one author, so I link the author with a foreign key.
>  
> Now I could point to a particular author with a url like this (to show the 
> details)
>  
> /mylibrary/author/32
>  
> I wish to put a button to add a new book and would like the CreateView 
> derived class handling the request to collect the author id (32 in this 
> case) so my form would automatically set the foreign key and make it 
> unchangeable from the client browser.
>  
> Now the questions are:
>  
> 1) would you oranize the url in a way like this?   (notice that 32 is the 
> author id)
> /mylibrary/book/32/addnewbook
>  
> 2) how do I extract the slug within my BookNew (derived from CreateNew)?
> url(r'^book/(?P<slug>\d+)/addnewbook, BookNew.as_view()),
>  
> seems not avaliable as in the context/template: {{ slug }}
>  
> Cheers,
> Giulio.
>  

One way to take care of this is to have a URL of
form /mylibrary/book/new?author_id=32. I.e. you'd pass the default
values for author ID via GET parameter, and based on that you'd set-up
the query set for your form widget inside of a view.

I think this is just one possible approach, of course. The thing is,
this way it might be a bit easier to extend the schema for other fields
by adding extra GET parameters, and you'd avoid redundancy and
duplication with URLs (i.e. there's just one and only one URL for adding
books).

Best regards

-- 
Branko Majic
Jabber: bra...@majic.rs
Please use only Free formats when sending attachments to me.

Бранко Мајић
Џабер: bra...@majic.rs
Молим вас да додатке шаљете искључиво у слободним форматима.

Attachment: signature.asc
Description: PGP signature

Reply via email to