Re: Populating form and having access to related objects

2011-09-16 Thread David
Javier That's great and working, thank you. I have modified my code and it appears to be working now. Does what I have done now account for the GET scenario please? Thanks again! def companyedit(request, pk): if request.method == 'POST': a = Company.objects.select_related().get(pk=pk

Re: Populating form and having access to related objects

2011-09-16 Thread Javier Guerra Giraldez
On Fri, Sep 16, 2011 at 10:57 AM, David wrote: > I had imagined therefore I would be able to iterate through the > Person's that belong to the Company using the following syntax: > > {% for p in person %} >        {{ p.first_name }} > {% endfor %} > > But I'm told that the company object is not it

Re: Populating form and having access to related objects

2011-09-16 Thread David
Is this because my Company model contains no foreign keys as the relationship is from Person to company and Person contains the foreign key? -- 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@google

Re: Populating form and having access to related objects

2011-09-16 Thread David
Hi Javier Thanks for your reply. I have modified my view like this: def companyedit(request, pk): if request.method == 'POST': a = Company.objects.select_related().get(pk=pk) form = CompanyForm(request.POST, instance=a) if form.is_valid(): form.save()

Re: Populating form and having access to related objects

2011-09-16 Thread David
I should add that Person has the foreign key relationship to Company. I know how to do this in SQL but not in the ORM. Thanks for any assistance. -- 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

Re: Populating form and having access to related objects

2011-09-16 Thread Javier Guerra Giraldez
On Fri, Sep 16, 2011 at 10:35 AM, David wrote: > def companyedit(request, pk): >    if request.method == 'POST': >        a = Company.objects.get(pk=pk) .. > I would like to fetch the related Person objects that are related to > Company (ie. those who work for said company). I don't intend to

Populating form and having access to related objects

2011-09-16 Thread David
Hello This is my view @login_required @transaction.commit_on_success def companyedit(request, pk): if request.method == 'POST': a = Company.objects.get(pk=pk) form = CompanyForm(request.POST, instance=a) if form.is_valid(): form.save() else: co