Hi,

I'm quiet new to django myself, so this may not be the definitive answer, but 
perhaps it would help.

I've done something similar, but I created my own view rather than using the 
generic view, and used a form to create the dependent object (the book in 
your case). I used the method forms.form_for_model to create a form based on 
the model, which I guess should be similar to what the generic create view 
does. When displaying the form returned by this method, a drop-down box was 
displayed for selecting the parent object (your Author), allowing the user to 
select the author.

Have you tried to not pass the author, and then saw what you get? It's a 
speculation, but it may work for you as I described.

If you do want to force a specific author - i.e., not to allow the user to 
select it - it's something different, but can be done, at least if you use 
your own view. If you have questions about how to do it, just ask.

Cheers,

Amit

ביום שישי 01 יוני 2007, 23:11, נכתב על ידי Sacher Khoudari:
> 
> Hello!
> 
> I'm new to Django, and are currently playing around a bit. I've
> finished the tutorial, and have just started a small sample app. I
> really like Django. Although its different to everything I have done
> before (I confess, it was only PHP, I don't know Rails, Tomcat, Zope
> or anything else), you can get into it very quickly. The tutorial is
> great, and I think I'm understanding the design philosophies.
> 
> But, I have some trouble with the generic views. They are great,
> really, but either they lack a simple feature I think they should
> have, or they lack some proper documentation, or I'm a idiot and don't
> know how to use Google.
> 
> Ok, given the following situation: I have two models, one depends on
> the other by a foreign key. Call them
> 
> class Author:
>     name = models.CharField(maxlength=32)
> 
> class Book:
>     author = models.ForeignKey( Author )
> 
> Now I can get a list of all authors in my database, a list of all
> books by author, details for each book, I can edit and delete each
> book... that works all fine. And, it's really easy to do that. But how
> can I add a book to an author? I mean, how do I call
> "django.views.generic.create_update.object_create" with "model=Book",
> and pass it the value for it's foreign key?
> 
> Here is the URL pattern I want to use:
> 
> urlpatterns = patterns('django.views.generic.create_update',
>      (r'^authors/(?P<slug>\w+)/add_book/$', 'object_create',
> dict(model=Book,slug_field='name')),
>  )
> 
> Ok, instead of the author's name (as slug) y could have used it's ID.
> But that doesn't matter. Anyway, doing this I get an error. I don't
> have the error message here right now (I'm sorry, I'm developing/
> playing around at home, but I don't have an internet access there, so
> I'm on another computer), but it tells me, that object_create does not
> expect this "slug" field. "object_id" doesn't work either. The
> documentation (even the open book) doesn't tell me anything about
> that. Google doesn't find much if I search for "object_create".
> 
> Any ideas/hints/solutions? Is this a missing feature? Or does Django
> lack this feature by intention? Or have I missed something? I don't
> want to teach you in philosophy or design goals, but I think this
> should be part of the generic views' features. It's a further simple
> (generic) action I would like to make use of.
> 
> Thanks!
> Sacher
> 
> 
> > 
> 

--~--~---------~--~----~------------~-------~--~----~
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