Python django.views.generic.edit.CreateView() Examples
The following are 9
code examples of django.views.generic.edit.CreateView().
You can vote up the ones you like or vote down the ones you don't like,
and go to the original project or source file by following the links above each example.
You may also want to check out all available functions/classes of the module
django.views.generic.edit
, or try the search function
.
Example #1
Source File: CRUD.py From djreservation with GNU General Public License v3.0 | 6 votes |
def get_create_view_class(self): class UCreateView(CreateView): def form_valid(self, form): self.object = form.save(commit=False) self.object.user = self.request.user self.object.save() return HttpResponseRedirect(self.get_success_url()) return UCreateView
Example #2
Source File: views.py From djangochannel with BSD 3-Clause "New" or "Revised" License | 6 votes |
def post(self, request, section, pk): form = MessageForm(request.POST) if form.is_valid(): form = form.save(commit=False) form.user = request.user form.topic_id = pk form.save() return redirect("/forum/section/{}/{}/?page=last".format(section, pk)) # class MessageCreate(LoginRequiredMixin, CreateView): # """Создание темы на форуме""" # model = Message # form_class = MessageForm # template_name = 'forum/topic-detail.html' # # def form_valid(self, form): # form.instance.user = self.request.user # form.instance.topic_id = self.kwargs.get("pk") # form.save() # return super().form_valid(form)
Example #3
Source File: views.py From dj4e-samples with MIT License | 5 votes |
def post(self, request, pk) : make = get_object_or_404(self.model, pk=pk) make.delete() return redirect(self.success_url) # Take the easy way out on the main table # These views do not need a form because CreateView, etc. # Build a form object dynamically based on the fields # value in the constructor attributes
Example #4
Source File: views.py From iguana with Creative Commons Attribution Share Alike 4.0 International | 5 votes |
def form_valid(self, form): form.instance.creator = self.request.user # NOTE: this is necessary here even though it is a CreateView, because # "ValueError: "<Project: test_project>" needs to have a value for # field "project" before this many-to-many relationship can be used." form.instance.save() form.instance.manager.add(self.request.user) # per default a user follows the project he created follow_project(self.request.user, form.instance) # and every developer follows the project, too for dev in form.cleaned_data["developer"]: follow_project(dev, form.instance) return super(ProjectCreateView, self).form_valid(form)
Example #5
Source File: views.py From iguana with Creative Commons Attribution Share Alike 4.0 International | 5 votes |
def form_valid(self, form): form.instance.project = Project.objects.get(name_short=self.kwargs.get('project')) form.instance.creator = self.request.user # NOTE: this is necessary here even though it is a CreateView, because # otherwise the reversematch in signals.create.send fails form.instance.save() signals.create.send(sender=self.model, instance=form.instance, user=self.request.user) return super(IssueCreateView, self).form_valid(form)
Example #6
Source File: test_edit.py From djongo with GNU Affero General Public License v3.0 | 5 votes |
def test_create_view_with_restricted_fields(self): class MyCreateView(CreateView): model = Author fields = ['name'] self.assertEqual(list(MyCreateView().get_form_class().base_fields), ['name'])
Example #7
Source File: test_edit.py From djongo with GNU Affero General Public License v3.0 | 5 votes |
def test_create_view_all_fields(self): class MyCreateView(CreateView): model = Author fields = '__all__' self.assertEqual(list(MyCreateView().get_form_class().base_fields), ['name', 'slug'])
Example #8
Source File: test_edit.py From djongo with GNU Affero General Public License v3.0 | 5 votes |
def test_create_view_without_explicit_fields(self): class MyCreateView(CreateView): model = Author message = ( "Using ModelFormMixin (base class of MyCreateView) without the " "'fields' attribute is prohibited." ) with self.assertRaisesMessage(ImproperlyConfigured, message): MyCreateView().get_form_class()
Example #9
Source File: test_edit.py From djongo with GNU Affero General Public License v3.0 | 5 votes |
def test_define_both_fields_and_form_class(self): class MyCreateView(CreateView): model = Author form_class = AuthorForm fields = ['name'] message = "Specifying both 'fields' and 'form_class' is not permitted." with self.assertRaisesMessage(ImproperlyConfigured, message): MyCreateView().get_form_class()