Thanks for your reply :-) So there's no way to use a model form to proccess the quest and manually set just the FK of it?
Keir On Tuesday, October 2, 2012 6:18:21 AM UTC+1, Laxmikant Gurnalkar wrote: > > Sorry, see again!! > > def payments_view(request, contact_id): > payment = Payment() > contact = contact.objects.filter(id=contact_id) > if contact: > payment.contact = contact[0] > payment.save() > > > I dont think you are looking for this kind of thing : > cheers > > On Tue, Oct 2, 2012 at 10:42 AM, Laxmikant Gurnalkar < > laxmikant...@gmail.com <javascript:>> wrote: > >> def payments_view(request, contact_id): >> payment = Payment() >> payment.contact = contact[0] >> >>> 'contact': contact, 'payments': payments, 'form' : PaymentForm() >>> }) >>> return render_to_response('CRMSite/contact_payments.html',rctx) >>> >> rctx = RequestContext(request,{ >> On Tue, Oct 2, 2012 at 4:20 AM, Keir Lawson <keirl...@gmail.com<javascript:> >> > wrote: >> >>> Sorry if this is a dumb question, just picking up Django. >>> >>> I've set up a payments form, to create payments associated with a >>> contact (see payments model) however I'm having trouble figuring out how to >>> save the payment with the relevant contact associated, as the contact isnt >>> selected as part of the form (its in the URL instead). I've included both >>> the payment view and the view for processing it, my current approach >>> results in a validation error. Anyone able to help? >>> >>> Thanks >>> >>> Keir >>> >>> class Payment(models.Model): >>> amount = models.DecimalField(max_digits=10, decimal_places=2) >>> date = models.DateField() >>> contact = models.ForeignKey(Contact) >>> >>> def payments_view(request, contact_id): >>> contact = get_object_or_404(Contact, pk=contact_id) >>> payments = Payment.objects.filter(contact=contact_id) >>> rctx = RequestContext(request,{ >>> 'contact': contact, 'payments': payments, 'form' : PaymentForm() >>> }) >>> return render_to_response('CRMSite/contact_payments.html',rctx) >>> >>> def save_payment(request,contact_id): >>> PaymentForm(request.POST,contact=contact_id).save() >>> return payments_view(request, contact_id) >>> >>> -- >>> You received this message because you are subscribed to the Google >>> Groups "Django users" group. >>> To view this discussion on the web visit >>> https://groups.google.com/d/msg/django-users/-/g4cNoMI7bEoJ. >>> To post to this group, send email to django...@googlegroups.com<javascript:> >>> . >>> To unsubscribe from this group, send email to >>> django-users...@googlegroups.com <javascript:>. >>> For more options, visit this group at >>> http://groups.google.com/group/django-users?hl=en. >>> >> >> >> >> >> > > > -- > * > > GlxGuru > > * > -- You received this message because you are subscribed to the Google Groups "Django users" group. To view this discussion on the web visit https://groups.google.com/d/msg/django-users/-/UPZcFyHmGtMJ. 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.