Hi James,
Thanks very much for shearing your intellect, i really appreciate your help. It works perfectly well. i want the users who receive the email to be able to know who have apply for the leave: where it is highlighted blue i want to put like test user have apply for a leave. could you please advise how to do that.def email_authorizer(request):
email_obj = newleave.objects.order_by('-pk')[0]
if email_obj.department == 'GOV':
to_emails = [u.email for u in User.objects.filter(username__in=['sabiut'])]
send_mail("RBV Leave Application Email Testing", "You have received a leave application form. Please login to the leave system to Authorize the leave. \nPlease ignore this message, we are testing the new eLeave system!",
"RBV eLeave <Rbv_eLeave_System>", [to_emails])
return render_to_response('thankyou.html')
On Tue, Jan 27, 2015 at 6:03 PM, James Schneider <jrschneider83@gmail.com> wrote:
Instead of looping through the all() set of objects (which works quickly with small sets of objects, imagine >20K objects, that would be noticeably slower, probably seconds or more), you should just query the object you want directly using something like:obj = newleave.objects.order_by('-pk')[0]That would give you the newleave object that has the highest PK, and would presumably be the most recently added entry. No need for a loop, let the DB do the work in this case.I'm a bit confused by the logic in the for loop. You re-query newleave.objects.filter(department="GOV"), which would return a bunch of rows no matter what (based on the output you provided), and has no relation based on the object that you asked about initially. I don't think that does what you want, as it will send out an email every time no matter what, not just every time that obj.department == 'GOV' (which is probably the check you want instead).-James--On Mon, Jan 26, 2015 at 4:01 PM, sum abiut <suabiut@gmail.com> wrote:To view this discussion on the web visit https://groups.google.com/d/msgid/django-users/CAPCf-y4puiNqfe%2BFeoGzeYBRF8QkWYW6dUG2U_zdAcSDbzcjBA%40mail.gmail.com.Here is how it looks like, when a new row is added it display last.On Tue, Jan 27, 2015 at 10:51 AM, Stephen J. Butler <stephen.butler@gmail.com> wrote:Do you have a default ordering on the Model object? That is, an
ordering option on newleave.Meta? Because otherwise this query
"newleave.objects.all()" is not at all guaranteed to return rows in
the order they were added.
It may, by coincidence, in your current environment behave that way.
But change databases, or add more rows, or look at it funny, and that
won't be true.
> https://groups.google.com/d/msgid/django-users/CAPCf-y51_QA6iLbJnyvLQSkdL6SCu8x%3DO8P2vjVeWcBsd9rCWQ%40mail.gmail.com.
On Mon, Jan 26, 2015 at 5:38 PM, sum abiut <suabiut@gmail.com> wrote:
> Thank you for your email. I am iterating all the row to find out which row
> was recently added. basically when a row is added to it become last. so i am
> trying to comparing a column on the last row. which is the row that was
> recently add if the condition of the column is exist. that is when i send
> out email.
>
> hope my explanation is clear.
>
> Cheers
>
>
> On Tue, Jan 27, 2015 at 10:28 AM, Paul Royik <distantjob004@gmail.com>
> wrote:
>>
>> Inside view there is no forloop (unless you explicitly define it). forloop
>> is defined only inside for loops in templates
>>
>> Actually your code is somewhat weird.
>> You iterate all list until last without doing anything.
>>
>> It is more efficient to use slicing
>>
>> email = newleave.objects.all()[-1] # this is already last item
>> govoffice=newleave.objects.filter(department="GOV")
>> if govoffice.exists():
>> to_emails = [u.email for u in
>> User.objects.filter(username__in['testuser','sabiut'])]
>> send_mail("RBV Leave Application Email Testing", "You have
>> received a leave application form. Please login to the leave system to
>> Authorize the leave.",
>> "RBV eLeave <Rbv_eLeave_System>", [to_emails])
>> return render_to_response('thankyou.html')
>>
>> Other code is also not very understandable, but I can't help you, since
>> don't understand what should be done.
>>
>> --
>> You received this message because you are subscribed to the Google Groups
>> "Django users" group.
>> To unsubscribe from this group and stop receiving emails from it, send an
>> email to django-users+unsubscribe@googlegroups.com.
>> To post to this group, send email to django-users@googlegroups.com.
>> Visit this group at http://groups.google.com/group/django-users.
>> To view this discussion on the web visit
>> https://groups.google.com/d/msgid/django-users/ac2740f3-2e60-44f7-860d-974550476cd4%40googlegroups.com.
>> For more options, visit https://groups.google.com/d/optout.
>
>
>
>
> --
>
> --
> You received this message because you are subscribed to the Google Groups
> "Django users" group.
> To unsubscribe from this group and stop receiving emails from it, send an
> email to django-users+unsubscribe@googlegroups.com.
> To post to this group, send email to django-users@googlegroups.com.
> Visit this group at http://groups.google.com/group/django-users.
> To view this discussion on the web visit
>
> For more options, visit https://groups.google.com/d/optout.
--
You received this message because you are subscribed to the Google Groups "Django users" group.
To unsubscribe from this group and stop receiving emails from it, send an email to django-users+unsubscribe@googlegroups.com.
To post to this group, send email to django-users@googlegroups.com.
Visit this group at http://groups.google.com/group/django-users.
To view this discussion on the web visit https://groups.google.com/d/msgid/django-users/CAD4ANxX4Rw0ke_VnrEQHYt-1BgYo0Nouy3rbL%3Dk-Pnn4Sq%3DmUA%40mail.gmail.com.
For more options, visit https://groups.google.com/d/optout.
--
You received this message because you are subscribed to the Google Groups "Django users" group.
To unsubscribe from this group and stop receiving emails from it, send an email to django-users+unsubscribe@googlegroups.com.
To post to this group, send email to django-users@googlegroups.com.
Visit this group at http://groups.google.com/group/django-users.
You received this message because you are subscribed to the Google Groups "Django users" group.
To unsubscribe from this group and stop receiving emails from it, send an email to django-users+unsubscribe@googlegroups.com.
To post to this group, send email to django-users@googlegroups.com.
Visit this group at http://groups.google.com/group/django-users.
To view this discussion on the web visit https://groups.google.com/d/msgid/django-users/CA%2Be%2BciUG6gMsp%3DvS-qPW5_WhNUPmCMpXjRVVg1ehuyeONV%3Dwag%40mail.gmail.com.
--
You received this message because you are subscribed to the Google Groups "Django users" group.
To unsubscribe from this group and stop receiving emails from it, send an email to django-users+unsubscribe@googlegroups.com.
To post to this group, send email to django-users@googlegroups.com.
Visit this group at http://groups.google.com/group/django-users.
To view this discussion on the web visit https://groups.google.com/d/msgid/django-users/CAPCf-y6Oj68JM_V-ONamWX_vVAeRt%3DJZ%3DbovdxzAox9icCoPJQ%40mail.gmail.com.
For more options, visit https://groups.google.com/d/optout.
No comments:
Post a Comment