i am wondering how can i configure django admin to see a form, so the auth_user should send emails to subscribe users.
What i have done:
models.py
from django.db import models
from datetime import datetime
class Mail(models.Model):
email=models.EmailField(max_length=255,unique=True,help_text="Το email του χρήστη",verbose_name="Email")
timestamp=models.DateTimeField(default=datetime.now,help_text="Η ημερομηνία που ο χρήστης γράφτηκε στην newsletter list",verbose_name="Ημερομηνία εγγραφής")
delete_link=models.SlugField(unique=True,max_length=255,null=True,blank=True)
def __unicode__(self):
return self.email
class Meta:
verbose_name = "Email User"
verbose_name_plural = "Email Users"
forms.py
from django import forms
class MailForm(forms.Form):
subject = forms.CharField(max_length=255)
message = forms.CharField(widget=forms.Textarea)
attachment = forms.FileField()
I am trying to add one link to newsletter app in admin page.Example:
Now somehow, i must write the validation rules for the form (subject and message must not be blank).For validation i am trying to do something like:
def clean_subject(self):
if self.cleaned_data["subject"]=="" or self.cleaned_data["subject"]==None:
raise forms.ValidationError("My text goes here")
return self.cleaned_data["subject"]
def clean_message(self):
if self.cleaned_data["message"]=="" or self.cleaned_data["message"]==None:
raise forms.ValidationError("My text goes here")
return self.cleaned_data["message"]
And when the form is not valid django shows up a message like the standar way.Example:
Finally i must write 1 view to show the form (i am trying to use something standar for django admin, and 1 view with a message that says "Send 130 mails with success."
Any advice how can i configure django admin to do what i described would be usefull!