When I run this action in admin site (Send e-mail to selected people) i have error:
string indices must be integers, not unicode django on line: [p.user_email])
How to fix it?
from django.contrib import admin
from myproject.myapp.models import People
from django.core.mail import send_mail
def send_mail(modeladmin, request, queryset):
for p in queryset:
send_mail('People information', p.name, p.time, 'mymail@gmail.com'
[p.user_email])
send_mail.short_description = u'Send e-mail to selected people'
class PeopleAdmin(admin.ModelAdmin):
list_display = ('name', 'user_email','time')
actions = [send_mail]
admin.site.register(People, PeopleAdmin)
Actually, you forgot the comma after
'mymail@gmail.com', so it’s interpreting it as'mymail@gmail.com'[p.user_email], as if you were trying to index the string literal.