For the first question, the db-api doc should provide this and more information, as I am not sure I completely understand, but here goes (assuming the following models):
class B(models.Model): attribute = char()... class A(models.Model): attribute = char()... bs = m2m(B) in your view to get all of the B(s) related to a given A a = A.objects.get(pk=1) b = a.bs.all() if you want to get all of the Bs that are related to 'any' A: b = B.objects.filter(a__isnull = False) for question 2, I am not sure what you mean, if you mean can you create a B without relating it to an A? sure, a related A is not required by B. If you do not want to require a B for A just set 'blank=True, null=True' in the M2M field definition in A. Not sure if this helps, your original post was somewhat confusing, if you post relevant snippets from your models you may get more intelligent responses than my intellectual meanderings. -richard On 5/16/08, jabbercat <[EMAIL PROTECTED]> wrote: > > > Hello, > > it's my frist time I'm using this Group. > > My Problems: > I have a class A and a class B with a one(A)-to-many(B) relationship > between them. > > My first question: Is there an efficient way to get in a template all > instances of B, which are related to an instance of A, when i only > knew an instance of A? Something like a special attribute, or > something like that? > > My second question: I want to use form_for_model(), because of my > database-driver design. But how can I add an instance of B so that the > relation to an instance of A is also saved, without specify the > foreign key id of A explicitly? > > I hope you understand what I meen. > > > --~--~---------~--~----~------------~-------~--~----~ 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 -~----------~----~----~----~------~----~------~--~---