On Oct 20, 11:12 am, simong <[EMAIL PROTECTED]> wrote:
>         if request.method == 'POST':
>                 orderform = OrderForm(request.POST)
>                 if orderform.is_valid():
>                         preorder = orderform.save(commit=False)
>                         orderno  = '%04d' % (preorder.id)
>                         preorder.orderno = orderno
>                         preorder.cartid = cartid
>                         preorder.save()
>
> I do the uncommited save to get pk to pad it for an order number.
> However, at orderform.save, I am now getting the eternally helpful
> error
>
> <type 'exceptions.TypeError'>: coercing to Unicode: need string or
> buffer, NoneType found.
>

I assume the error is happening at the line:
orderno  = '%04d' % (preorder.id)
I'm not sure what you're expecting to happen here. You explicitly call
commit=False on the form save, so the model isn't saved to the
database and preorder won't have an id. Then you attempt to use that
non-existent id - unsurprisingly, Python can't convert None into a
four-digit number.

If your 'orderno' field is simply a four-digit padded version of the
pk field, you would probably be better of providing a model method to
get that, rather than saving it twice to the database.

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