The intend of class based-views is that you can subclass to add concrete functionality once, or create a mixin to apply some functionality to several concrete subclasses.

The following example illustrates a mixin that overrides just the get_for method, to be used with a class that inherits from CreateView: ::

nano views.py
from django.views.generic.edit import CreateView
from django.contrib.auth.models import User
from django.shortcuts import redirect
from django.core.urlresolvers import reverse_lazy
from django.contrib import messages
from django.db import IntegrityError

from data import Entry

class ExcludeUserFieldMixin(object):
    def get_form(self, form_class):
        super(ExcludeUserFieldMixin, self).get_form(form_class)
        form = form_class()
        del form.fields['user']
        print 'Deleted User'
        return form

class CreateEntryView(ExcludeUserFieldMixin, CreateView):
    model = Entry
    success_url = reverse_lazy('create_entry')
    template_name = 'data/entry_form.html'

    def form_valid(self, form):
        self.object = form.save(commit=False)
        self.object.user = User.objects.get(pk=1)
            messages.sucess(self.request, "Saved the entry successfully")
            return redirect(self.get_success_url())
        except IntegrityError:
            messages.error(self.request, "Duplicate entry name. Entry already exist")
        super(CreateEntryView, self).form_valid(form)

Edit post (Admin)

Comment on This Data Unit