Paul,

Your form logic will go on your Form (or ModelForm) definition, not on the
view. As the docs [1] say, CreateView is a combination of ModelFormMixin and
ProcessFormView. Please read the docs on those two mixins to understand what
methods your CampaignCreate class can override, but do move the form logic
(i.e. field excluding, validation, etc) to a custom form.

Try something like (the following code hasn't been tested):

# views.py
class CampaignCreate(CreateView):
    template_name = "forms/create.html"
    form_class = CampaignForm


# forms.py
class CampaingForm(forms.ModelForm)
    class Meta:
        model = Campaign
        exclude = ('user', 'name', 'content_inlined')


Hope that helps!


Cheers,
André


[1]
https://docs.djangoproject.com/en/dev/ref/class-based-views/#django.views.generic.edit.CreateView



On Fri, Jul 15, 2011 at 6:18 AM, Paul Walsh <paulywa...@gmail.com> wrote:

> I am pretty new to Django - new enough to be developing my first Django app
> on 1.3. So, I am basing all my work on class-based generic views, and have
> never used the older generic view functions.
>
> A problem I have is the lack of examples and documentation on the new
> class-based generic views.
>
> My current problem is that I am trying to build some forms based on models.
> I am not using Django Forms (ModelForm), but rather CreateView. CreateView
> gets me almost there, but I can't find any documentation on (1) how to
> exclude fields, and (2) how to fix a value for a field.
>
> My class is like so:
>
> class CreateCampaignView(CreateView):
> model = Campaign
> template_name = "forms/create.html"
>
> I tried exclude from ModelForms, like this:
>
> class CreateCampaignView(UserAccountCreateView):
> model = Campaign
>  template_name = "forms/create.html"
>         exclude = ('user', 'name', 'content_inlined')
>
> and that doesn't work. Is there another way to exclude fields using
> CreateView?
>
> and, one of my excluded fields, "user", also needs to get the value of
> self.request.user
>
> I tried again here to apply the docs from ModelForms here for CreateView,
> but it doesn't work.
>
>
> Some might suggest I use Django Forms - it is a reasonable suggestion of
> course. But, being new, I don't have any "view legacy" and I just like the
> idea of working with class-based generic views where possible.
>
> thanks.
>
>
>  --
> You received this message because you are subscribed to the Google Groups
> "Django users" group.
> To view this discussion on the web visit
> https://groups.google.com/d/msg/django-users/-/g4ADYoJAbE0J.
> To post to this group, send email to django-users@googlegroups.com.
> To unsubscribe from this group, send email to
> django-users+unsubscr...@googlegroups.com.
> For more options, visit this group at
> http://groups.google.com/group/django-users?hl=en.
>

-- 
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 
django-users+unsubscr...@googlegroups.com.
For more options, visit this group at 
http://groups.google.com/group/django-users?hl=en.

Reply via email to