Re: Retrieving an ID from a posted form

2010-04-22 Thread Nick
works like a charm, thanks Ian.

On Apr 22, 10:02 am, Ian Lewis  wrote:
> Nick,
>
> Because you won't get an id for your newly created object before you
> save it you'll need to send the email after you save the form. I'm
> assuming that ArtistFormFinal is a ModelForm but you can get the id
> using something like the following:
>
> myobj = form.save()
> send_mail(subject, "Your id is %d!" % myobj.id, email_address, recipients)
>
> I hope that's what you were looking for.
>
> Ian
>
>
>
> On Thu, Apr 22, 2010 at 11:39 PM, Nick  wrote:
> > I am working on a form process with multiple levels of submission. The
> > first is a front facing form with a general set of questions that are
> > to be followed up by someone after the form is submitted (the form
> > submits and entry to the DB).  To cut down on the amount of hunting
> > that those who will be reviewing the forms have to do I'd like to be
> > able to retrieve the ID for the newly created DB entry and attach it
> > to a url that points directly to that entry in the django admin.
>
> > I have the email logic set up so that the form submits all of the
> > information via email to an individual. In the email is the link to
> > the admin. So far it just goes to a full list of entries:
>
> > ex.http://mydjango.site.com/admin/projects/app/model_name/ID
>
> > I can easily send everything up to the ID. How do i retrieve the ID
> > from the submitted form. Since this is adding an entry to the DB it
> > has to be creating an ID somewhere.  Here is my view:
>
> > def short_form(request):
> >if request.method == 'POST':
> >form = ArtistFormFinal(request.POST, request.FILES)
> >if form.is_valid():
> >name = form.cleaned_data['name']
> >year_created = form.cleaned_data['year_created']
> >home_city = form.cleaned_data['home_city']
> >home_state = form.cleaned_data['home_state']
> >genre = form.cleaned_data['genre']
> >email_address = form.cleaned_data['email_address']
> >phone_number = form.cleaned_data['phone_number']
> >website = form.cleaned_data['website']
> >audio = form.cleaned_data['audio_file']
> >subject = 'Static artists submission from %s' % (name)
> >message = render_to_string('static/short_email.txt', {
> >'name': name,
> >'year_created': year_created,
> >'home_city': home_city,
> >'genre': genre,
> >'home_state': home_state,
> >'email_address': email_address,
> >'phone_number': phone_number,
> >'website': website,
> >'audio': audio
> >})
> >recipients = ['ntankers...@opubco.com',
> > 'crobi...@opubco.com']
> >send_mail(subject, message, email_address, recipients,
> > fail_silently=False)
> >form.save()
> >return HttpResponseRedirect('thanks')
> >else:
> >form = ArtistFormFinal()
> >return render_to_response('static/artist_short.html',
> > {'form':form})
>
> > --
> > You received this message because you are subscribed to the Google Groups 
> > "Django users" group.
> > To post to this group, send email to django-us...@googlegroups.com.
> > To unsubscribe from this group, send email to 
> > django-users+unsubscr...@googlegroups.com.
> > For more options, visit this group 
> > athttp://groups.google.com/group/django-users?hl=en.
>
> --
> ===
> 株式会社ビープラウド  イアン・ルイス
> 〒150-0021
> 東京都渋谷区恵比寿西2-3-2 NSビル6階
> email: ianmle...@beproud.jp
> TEL:03-6416-9836
> FAX:03-6416-9837http://www.beproud.jp/
> ===
>
> --
> You received this message because you are subscribed to the Google Groups 
> "Django users" group.
> To post to this group, send email to django-us...@googlegroups.com.
> To unsubscribe from this group, send email to 
> django-users+unsubscr...@googlegroups.com.
> For more options, visit this group 
> athttp://groups.google.com/group/django-users?hl=en.

-- 
You received this message because you are subscribed to the Google Groups 
"Django users" group.
To post to this group, send email to django-us...@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.



Re: Retrieving an ID from a posted form

2010-04-22 Thread Ian Lewis
Nick,

Because you won't get an id for your newly created object before you
save it you'll need to send the email after you save the form. I'm
assuming that ArtistFormFinal is a ModelForm but you can get the id
using something like the following:

myobj = form.save()
send_mail(subject, "Your id is %d!" % myobj.id, email_address, recipients)

I hope that's what you were looking for.

Ian

On Thu, Apr 22, 2010 at 11:39 PM, Nick  wrote:
> I am working on a form process with multiple levels of submission. The
> first is a front facing form with a general set of questions that are
> to be followed up by someone after the form is submitted (the form
> submits and entry to the DB).  To cut down on the amount of hunting
> that those who will be reviewing the forms have to do I'd like to be
> able to retrieve the ID for the newly created DB entry and attach it
> to a url that points directly to that entry in the django admin.
>
> I have the email logic set up so that the form submits all of the
> information via email to an individual. In the email is the link to
> the admin. So far it just goes to a full list of entries:
>
> ex. http://mydjango.site.com/admin/projects/app/model_name/ID
>
> I can easily send everything up to the ID. How do i retrieve the ID
> from the submitted form. Since this is adding an entry to the DB it
> has to be creating an ID somewhere.  Here is my view:
>
> def short_form(request):
>if request.method == 'POST':
>form = ArtistFormFinal(request.POST, request.FILES)
>if form.is_valid():
>name = form.cleaned_data['name']
>year_created = form.cleaned_data['year_created']
>home_city = form.cleaned_data['home_city']
>home_state = form.cleaned_data['home_state']
>genre = form.cleaned_data['genre']
>email_address = form.cleaned_data['email_address']
>phone_number = form.cleaned_data['phone_number']
>website = form.cleaned_data['website']
>audio = form.cleaned_data['audio_file']
>subject = 'Static artists submission from %s' % (name)
>message = render_to_string('static/short_email.txt', {
>'name': name,
>'year_created': year_created,
>'home_city': home_city,
>'genre': genre,
>'home_state': home_state,
>'email_address': email_address,
>'phone_number': phone_number,
>'website': website,
>'audio': audio
>})
>recipients = ['ntankers...@opubco.com',
> 'crobi...@opubco.com']
>send_mail(subject, message, email_address, recipients,
> fail_silently=False)
>form.save()
>return HttpResponseRedirect('thanks')
>else:
>form = ArtistFormFinal()
>return render_to_response('static/artist_short.html',
> {'form':form})
>
> --
> You received this message because you are subscribed to the Google Groups 
> "Django users" group.
> To post to this group, send email to django-us...@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.
>
>



-- 
===
株式会社ビープラウド  イアン・ルイス
〒150-0021
東京都渋谷区恵比寿西2-3-2 NSビル6階
email: ianmle...@beproud.jp
TEL:03-6416-9836
FAX:03-6416-9837
http://www.beproud.jp/
===

-- 
You received this message because you are subscribed to the Google Groups 
"Django users" group.
To post to this group, send email to django-us...@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.



Retrieving an ID from a posted form

2010-04-22 Thread Nick
I am working on a form process with multiple levels of submission. The
first is a front facing form with a general set of questions that are
to be followed up by someone after the form is submitted (the form
submits and entry to the DB).  To cut down on the amount of hunting
that those who will be reviewing the forms have to do I'd like to be
able to retrieve the ID for the newly created DB entry and attach it
to a url that points directly to that entry in the django admin.

I have the email logic set up so that the form submits all of the
information via email to an individual. In the email is the link to
the admin. So far it just goes to a full list of entries:

ex. http://mydjango.site.com/admin/projects/app/model_name/ID

I can easily send everything up to the ID. How do i retrieve the ID
from the submitted form. Since this is adding an entry to the DB it
has to be creating an ID somewhere.  Here is my view:

def short_form(request):
if request.method == 'POST':
form = ArtistFormFinal(request.POST, request.FILES)
if form.is_valid():
name = form.cleaned_data['name']
year_created = form.cleaned_data['year_created']
home_city = form.cleaned_data['home_city']
home_state = form.cleaned_data['home_state']
genre = form.cleaned_data['genre']
email_address = form.cleaned_data['email_address']
phone_number = form.cleaned_data['phone_number']
website = form.cleaned_data['website']
audio = form.cleaned_data['audio_file']
subject = 'Static artists submission from %s' % (name)
message = render_to_string('static/short_email.txt', {
'name': name,
'year_created': year_created,
'home_city': home_city,
'genre': genre,
'home_state': home_state,
'email_address': email_address,
'phone_number': phone_number,
'website': website,
'audio': audio
})
recipients = ['ntankers...@opubco.com',
'crobi...@opubco.com']
send_mail(subject, message, email_address, recipients,
fail_silently=False)
form.save()
return HttpResponseRedirect('thanks')
else:
form = ArtistFormFinal()
return render_to_response('static/artist_short.html',
{'form':form})

-- 
You received this message because you are subscribed to the Google Groups 
"Django users" group.
To post to this group, send email to django-us...@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.