django-class-based-views

Django class based views - UpdateView with two model forms - one submit

狂风中的少年 提交于 2019-11-28 20:55:57
I have a page with a list of users, and would like to be able to click a link to update their profile. When 'update' is clicked, I should be able to edit the username, first name, ... email, phone number, department etc, in a single page, using a single submit button. I accomplished this by using two forms, one for User, and one for the extra information. The ListView, DeleteView and CreateView work perfectly with these two forms, but not the UpdateView. I am not able to instantiate the two forms with initial data. The question is: how do I instantiate the two forms with data? Overwrite self

django createview how to get the object that is created

人走茶凉 提交于 2019-11-28 20:12:08
i've two concatenated form. Basically user fills in the first form and then is redirected to the second one which adds value to the data of the first form. E.G. I've a form Movie (first form) and then i'm redirected to the form (actor) which add the actor to the movie. in my case the Movie = Chiamata and Actor = Offerta (i keep the italians name for what i need :D) fine. those are my urls in the urls.py url(r'^chiamata/$', ChiamataCreate.as_view(),name='chiamata_create'), url(r'^chimamata/(?P<pk>\d+)/offerta$', OffertaCreate.as_view(), name='offerta_create'), i've this create view class

Django, name parameter in urlpatterns

北慕城南 提交于 2019-11-28 17:46:24
I'm following a tutorial where my urlpatterns are: urlpatterns = patterns('', url(r'^passwords/$', PasswordListView.as_view(), name='passwords_api_root'), url(r'^passwords/(?P<id>[0-9]+)$', PasswordInstanceView.as_view(), name='passwords_api_instance'), ...other urls here..., ) The PasswordListView and PasswordInstanceView are supposed to be class based views. I could not figure out the meaning of the name parameter. Is it a default parameter passed to the view? No. It is just that django gives you the option to name your views in case you need to refer to them from your code, or your

How to subclass django's generic CreateView with initial data?

a 夏天 提交于 2019-11-28 17:35:47
I'm trying to create a dialog which uses jquery's .load() function to slurp in a rendered django form. The .load function is passed the pk of the "alert" object. Also available in the class functions are things like self.request.user so I can pre-fill those fields, shown below in the Message model (models.py): class Message(models.Model): user = models.ForeignKey(User) alert = models.ForeignKey(Alert) date = models.DateTimeField() message = models.TextField() Subclassing django's CreateView makes it pretty easy to generate a context with an instance of the ModelForm (views.py): class

Updating User model in Django with class based UpdateView

社会主义新天地 提交于 2019-11-28 17:30:44
I am trying to update the Django User model with the class based UpdateView that automatically renders with the current user but am getting an error that a pk or slug is required. The form work and renders with the proper current user context but throws the error when I try to submit the changes. Below is the view I am using: class UserUpdateView(UpdateView): form_class = UserForm model = User template_name = 'members/user_update.html' def get(self, request, **kwargs): self.object = User.objects.get(username=self.request.user) form_class = self.get_form_class() form = self.get_form(form_class)

Django combine DetailView and FormView

丶灬走出姿态 提交于 2019-11-28 17:13:38
问题 I have a view where I need to display information about a certain model instance hence I use a DetailView . I also need that same view to handle a regular form (not a model form), both displaying the form on GET and validating it on POST . To do that, I am trying to use a FormView however the combination of both view clases does not work: class FooView(FormView, DetailView): # configs here In GET (for simplicity of the question I will only show the issue with GET since POST has a different

Django class-based CreateView and UpdateView with multiple inline formsets

谁都会走 提交于 2019-11-28 16:51:59
问题 I have been trying to do Django class-based CreateView and UpdateView with multiple inline formsets CreateView works fine but UpdateView is not working properly, If anyone tried UpdateView with multiple inline formsets, anyone tried pls share updateview code snippet. # models.py from django.db import models class Recipe(models.Model): title = models.CharField(max_length=255) description = models.TextField() class Ingredient(models.Model): recipe = models.ForeignKey(Recipe) description =

Django. A good tutorial for Class Based Views [closed]

南楼画角 提交于 2019-11-28 16:50:00
问题 Closed. This question is off-topic. It is not currently accepting answers. Want to improve this question? Update the question so it's on-topic for Stack Overflow. Closed 6 years ago . Is there any good tutorial for learn how to use Class Based Generics Views in Django? I think that the documentation is not quite good and i'm a little bit lost when i try to do not usual things with the ListView, DetailView, CreateView, UpdateView and the other ones. I've read the Django documentation , The

What is the advantage of Class-Based views?

最后都变了- 提交于 2019-11-28 15:17:21
I read today that Django 1.3 alpha is shipping, and the most touted new feature is the introduction of class-based views . I've read the relevant documentation , but I find difficult to see the big advantage™ that I could get by using them, so I'm asking here for some help in understanding them. Let's take an advanced example from the documentation. urls.py from books.views import PublisherBookListView urlpatterns = patterns('', (r'^books/(\w+)/$', PublisherBookListView.as_view()), ) views.py from django.shortcuts import get_object_or_404 from django.views.generic import ListView from books

Getting __init__() got an unexpected keyword argument 'instance' with CreateView of Django

余生长醉 提交于 2019-11-28 10:40:51
Some details: Request Method: GET Request URL: http://localhost:8080/user/create Django Version: 1.5.1 Exception Type: TypeError Exception Value: ____init____() got an unexpected keyword argument 'instance' Exception Location: /place/venv/local/lib/python2.7/site-packages/django/views/generic/edit.py in get_form, line 35 Python Executable: /place/venv/bin/python Python Version: 2.7.3 views.py class UserCreateView(CreateView): model = models.User form_class = forms.UserForm urls.py url(r'^user/create$', UserCreateView.as_view(), name='user_create'), forms.py class UserForm(forms.Form): GROUP