class-based-views

Django: CreateView with additional field?

无人久伴 提交于 2019-12-07 07:10:24
问题 I am trying to program a Django CreateView (CBV), which takes instead of the user id the user email and determines (or creates) the user based on the email. My model does not contain anything special: class Project(models.Model): name = models.CharField(_('Title'), max_length=100,) user = models.ForeignKey(User, verbose_name=_('user'),) ... My forms.py adds the additional email field to the form: class ProjectCreateForm(forms.ModelForm): email = forms.EmailField(required=True, ) class Meta:

Django: model object “has no attribute '_meta'” in class based view

旧街凉风 提交于 2019-12-06 23:59:29
问题 Hi Stackoverflow people, I am working with class based views and for a test site, I followed the documentation to setup the class based views. For a project site (based on the project model below), I just want to create a quick CRUD application for the simple project model below. models.py class Project(models.Manager): name = models.CharField(_('Name of the Project'), max_length = 100,) slug = models.SlugField(max_length=100,) ... views.py from django.views.generic.edit import CreateView,

Using Multiple ModelForms with Class-Based Views

萝らか妹 提交于 2019-12-06 20:26:24
I've got a situation where I'd like to add an additional modelform to my CreateView. We have an entry order system that allows someone to add an order and then add items to that order. Typically, when someone adds an order for the first time they'd like to also add an item to that order, so I want to combine those models into a single form and process them on initial order entry. I'm running into a problem when the forms don't validate. I've overridden get_context_data to add the item form to the template and I've overridden post to process the extra form. But when the forms are invalid I need

How to apply decorator do dispatch method in class-based views Django

旧街凉风 提交于 2019-12-06 08:29:02
问题 Reading a 'ProDjango' book, I've found interesting moment about applying custom decorator to methods in class-based views. Author says that we can either manually assign decorator to each method of class, i.e., get , post and so on, or we can add our decorator to dispatch() method and if we do so then decorator will be applied to each method of class( get , post etc) Question is: How actually I can apply decorator to dispatch() method of Class-based view? 回答1: You can use the decorator method

Django: CreateView with additional field?

走远了吗. 提交于 2019-12-05 12:39:18
I am trying to program a Django CreateView (CBV), which takes instead of the user id the user email and determines (or creates) the user based on the email. My model does not contain anything special: class Project(models.Model): name = models.CharField(_('Title'), max_length=100,) user = models.ForeignKey(User, verbose_name=_('user'),) ... My forms.py adds the additional email field to the form: class ProjectCreateForm(forms.ModelForm): email = forms.EmailField(required=True, ) class Meta: model = Project fields = ('name', ...,) In my views.py, I am trying to determine if the user exists or

Django: model object “has no attribute '_meta'” in class based view

醉酒当歌 提交于 2019-12-05 04:05:08
Hi Stackoverflow people, I am working with class based views and for a test site, I followed the documentation to setup the class based views. For a project site (based on the project model below), I just want to create a quick CRUD application for the simple project model below. models.py class Project(models.Manager): name = models.CharField(_('Name of the Project'), max_length = 100,) slug = models.SlugField(max_length=100,) ... views.py from django.views.generic.edit import CreateView, UpdateView, DeleteView from django.core.urlresolvers import reverse_lazy from project.models import

Django: ListView with post() method?

你。 提交于 2019-12-04 23:32:22
问题 I am trying to process two forms in a Django class based view. The site contains a form called form (based on GET ) for narrowing the list results of the ListView and the second form status_form (based on POST ). Both forms are required since the ListView returns a list of items. Form lets the user restrict the choices and status_forms lets the user flag incorrect items via a modal form (therefore it needs to be in the same template). My trouble is that ListView does not come with the method

How to apply decorator do dispatch method in class-based views Django

天涯浪子 提交于 2019-12-04 14:06:18
Reading a 'ProDjango' book, I've found interesting moment about applying custom decorator to methods in class-based views. Author says that we can either manually assign decorator to each method of class, i.e., get , post and so on, or we can add our decorator to dispatch() method and if we do so then decorator will be applied to each method of class( get , post etc) Question is: How actually I can apply decorator to dispatch() method of Class-based view? schillingt You can use the decorator method_decorator as shown here in the docs . From the docs: from django.contrib.auth.decorators import

Django: ListView with post() method?

僤鯓⒐⒋嵵緔 提交于 2019-12-03 14:17:10
I am trying to process two forms in a Django class based view. The site contains a form called form (based on GET ) for narrowing the list results of the ListView and the second form status_form (based on POST ). Both forms are required since the ListView returns a list of items. Form lets the user restrict the choices and status_forms lets the user flag incorrect items via a modal form (therefore it needs to be in the same template). My trouble is that ListView does not come with the method post , however FormView does. My class List inherits from both classes, but when I execute the class I

How to redirect on conditions with class based views in Django 1.3?

时光总嘲笑我的痴心妄想 提交于 2019-12-03 10:40:26
问题 I am using a ListView that list videos according to tags. The filtering happens in get_queryset(). I'd like to redirect the user to another page if the tag doesn't contains any video. With a function, it would be easy. Query, check the queryset, redirect. With a class, I fail doing so: class VideosView(generic.ListView): def get_queryset(self): """ This work. """ tag = self.kwargs.get('tag', None) self.videos = Video.on_site.all() if tag: self.videos = Video.tagged.with_all(tag, self.videos)

工具导航Map