What is the best way to modify form data before it is saved to the
database?

I have tried the following but can't seem to get it to work, can
anyone help?

models.py
------------------

class MailBox(models.Model):

        domain = models.ForeignKey(Domain, core=True)
        address = models.CharField(max_length=500)
        password = models.CharField(max_length=500)
        maildir = models.CharField(max_length=500)

        def __str__(self):
                return self.address


forms.py
------------------

from django import forms
from django.forms import ModelForm, ModelChoiceField
from mysite.hosting.models import *
from django.forms.util import ValidationError
import crypt

class MailBoxForm(ModelForm):
        class Meta:
                model = MailBox

        def clean_Password(self):

                return crypt.crypt(self.data['Password'], '$1$salt')

views.py
--------------------

@login_required
def test(request, domain_id):

        if request.method == 'POST':
                form = MailBoxForm(request.POST)

                if form.is_valid():
                        new_form = form.save()
 
request.user.message_set.create(message="Mailbox created")

        else:

                form = MailBoxForm()

        return render_to_response('test.html', {"form": form,  },
context_instance=RequestContext(request))


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