class-based-views

Using Multiple ModelForms with Class-Based Views

对着背影说爱祢 提交于 2019-12-23 00:48:34
问题 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

How to do a DetailView in django 1.3?

一个人想着一个人 提交于 2019-12-20 10:55:51
问题 I'm currently learning how to use the class-based views in django 1.3. I'm trying to update an application to use them, but I still don't uderstand very well how they work (and I read the entire class-based views reference like two or three times EVERY day). To the question, I have an space index page that needs some extra context data, the url parameter is a name (no pk, and that can't be changed, it's the expected behaviour) and the users that don't have that space selected in their

Overriding Flask add_url_rule to route a specific URL

大憨熊 提交于 2019-12-13 16:03:19
问题 I'm using the class-based views in Flask for creating a CRUD REST API and registering the routes using add_url_rule like so... class GenericAPI(MethodView): def get(self, item_group, item_id): ... def post(self, item_group, item_id): ... ... api_view = GenericAPI.as_view('apps_api') app.add_url_rule('/api/<item_group>', defaults={'item_id': None}, view_func=api_view, methods=['GET',]) app.add_url_rule('/api/<item_group>/<item_id>', view_func=api_view, methods=['GET',]) app.add_url_rule('/api/

Class-based and Object-based languages comparison (ECMAScript Specification)

久未见 提交于 2019-12-12 07:38:28
问题 In a class-based object-oriented language, in general, state is carried by instances, methods are carried by classes, and inheritance is only of structure and behaviour. In ECMAScript, the state and methods are carried by objects, while structure, behaviour, and state are all inherited. This is the snippet from ECMAScript Specification June 2015. I don't understant parts of this text. State is carried by instances - what does state mean in this context and example of this (c++ is preferred)

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