class-based-views

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)

How to do a DetailView in django 1.3?

老子叫甜甜 提交于 2019-12-03 00:40:37
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 profiles can't enter it. My function-based code (working fine): def view_space_index(request, space_name):

Is it possible to have a form in a ListView template?

限于喜欢 提交于 2019-12-01 13:38:30
I built a listview which works fine and gives me exactly what I want. In the template of this ListView I declared a form that points to a CreateView. The form is like so, {% if user.is_authenticated %} <form action="{% url 'post_wall' %}" method="POST"> {% csrf_token %} <input type='text' name='body' /> <input type='hidden' name='from_user' value='{{ user.id }}' /> <input type='hidden' name='to_user' value='{{ to_user }}' /> <input type='submit' value='POST'/> </form> {% endif %} the post_wall url corresponds to url(r'accounts/post_wall', WallCreate.as_view(), name='post_wall'), The url which

Is it possible to have a form in a ListView template?

半世苍凉 提交于 2019-12-01 11:39:00
问题 I built a listview which works fine and gives me exactly what I want. In the template of this ListView I declared a form that points to a CreateView. The form is like so, {% if user.is_authenticated %} <form action="{% url 'post_wall' %}" method="POST"> {% csrf_token %} <input type='text' name='body' /> <input type='hidden' name='from_user' value='{{ user.id }}' /> <input type='hidden' name='to_user' value='{{ to_user }}' /> <input type='submit' value='POST'/> </form> {% endif %} the post

How to access RequestContext in class-based generic views?

元气小坏坏 提交于 2019-11-30 22:02:35
问题 I have this path in my urls.py: archive_index_dict = { 'queryset': News.objects.filter(show=True), 'date_field': 'date', 'template_object_name': 'object_list', } ... url(r'^$', 'django.views.generic.date_based.archive_index', archive_index_dict, name='news_archive_index' ), Now I want to detect in template if a page is current (this is for menu styling). Neither {{ request.path }} nor {{ request.get_full_path }} work in template. What should I use instead? SOLUTION To get request available in

How do I pass a parent id as an fk to child object's ModelForm using generic class-based views in Django?

半腔热情 提交于 2019-11-29 12:43:11
I am trying to use Django Generic Class-Based Views to build a CRUD interface to a two-model database. I have a working CRUD interface to the parent model, and am stuck trying to get the child Create working. For consistency with other Django examples, take the parent to be Author and the child to be Book. What is the simplest way to allow users to add Books to an Author? In HTML terms, I think that I want to make a link on the Author detail page that includes the ID of the Author, have that ID be pre-set on the Book form, and then have the Book form processing use that ID as the PK of the

How do I pass a parent id as an fk to child object's ModelForm using generic class-based views in Django?

China☆狼群 提交于 2019-11-28 06:07:51
问题 I am trying to use Django Generic Class-Based Views to build a CRUD interface to a two-model database. I have a working CRUD interface to the parent model, and am stuck trying to get the child Create working. For consistency with other Django examples, take the parent to be Author and the child to be Book. What is the simplest way to allow users to add Books to an Author? In HTML terms, I think that I want to make a link on the Author detail page that includes the ID of the Author, have that