I guess manipultors are made for this purpose. I'm not sure but you can
probably override AddManipulator in order to use generic views.

Hope this is the answer to your queston.

This is an example from my excercise blog app (it doesn't use  generic
view actually):

#model
class Entry(models.Model):
        headline = models.CharField(maxlength=100, default='Default headline')
        pub_date = models.DateTimeField(default=datetime.now())
        body = models.TextField()

        class Admin:
                pass

        def __str__(self):
                return self.headline


# Custom manipulator (I keep this code in views.py)
class NoDateAddManipulator(forms.Manipulator):
        def __init__(self):
                self.fields = (
                        forms.TextField(field_name="headline", 
is_required=True),
                        forms.LargeTextField(field_name="body", 
is_required=True),
                )
        def save(self,new_data):
                ########### Here you can make your altering
#############
                e = Entry(headline = new_data["headline"], body = 
new_data["body"])
                e.save()
                return e

# And the view
# this is copied form django docs (even comments stayed:D)

def add(request):
        manipulator = NoDateAddManipulator()
        if request.POST:
                new_data = request.POST.copy() # If data was POSTed, we're 
trying to
create a new Place.
                errors = manipulator.get_validation_errors(new_data)
                if not errors:
                        manipulator.do_html2python(new_data)
                        new_entry = manipulator.save(new_data)
                        return HttpResponseRedirect("/blog/%i/saved" % 
new_entry.id)
        else:
                errors = new_data = {} # No POST, so we want a brand new form 
without
any data or errors.
        # Create the FormWrapper, template, context, response.
        form = forms.FormWrapper(manipulator, new_data, errors)
        return render_to_response('blog/add_form.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-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
-~----------~----~----~----~------~----~------~--~---

Reply via email to