django-class-based-views

Bootstrap3 tabs in Django

穿精又带淫゛_ 提交于 2019-12-13 12:19:33
问题 I want to implement Bootstrap3 tabs in my app, which displays school data by state. So if you go to example.com/ma/ you will see information for the state of Massachusetts and tabs to sort by grade level. I am already using the queryset to filter by state so that on example.com/ma/ only "ma" results appear. And I can show ALL data in one of the tabs, but can't filter it out for multiple tabs. To keep it simple, I just want to do tabs for "All" and "High School" here. Here is my models.py :

Class Based Views (CBV), CreateView and request.user with a many-to-many relation

牧云@^-^@ 提交于 2019-12-13 07:26:05
问题 Based on the examples from https://docs.djangoproject.com/en/1.11/topics/class-based-views/generic-editing/#models-and-request-user - but with a many-to-many relation instead of a foreign key relation: models.py from django.contrib.auth.models import User from django.db import models class Author(models.Model): name = models.CharField(max_length=200) owners = models.ManyToManyField(User, related_name='owners_') views.py from django.views.generic.edit import CreateView from myapp.models import

Updating Custom User Model in Django with Class Based UpdateView

落爺英雄遲暮 提交于 2019-12-13 05:25:11
问题 I am using Django 1.7.1 with Python 3.4 . I created a custom user model and now I have a need for users to be able to update their details. What I need is that, when users go to the form to update their details, the form is pre-populated with their data i.e. username, email and so on. So far, the form is showing but not with the current user data. I have the following code: models.py from django.contrib.auth.models import AbstractBaseUser, BaseUserManager, PermissionsMixin ... # Some code

class based view passing parameters

扶醉桌前 提交于 2019-12-13 04:13:51
问题 I have just started using Class-based views and I am trying to pass the parameters to class-based view as: return HttpResponseRedirect(reverse('myView'), kwargs={'method': 'learning'}) My view is: class MyView(View): form_class = MyForm initial = {'key': 'value'} template_name = 'algoRunning.html' def dispatch(self, request, *args, **kwargs): print (kwargs['method']) data = self.readFile('myFile.txt') context = {'result': data} return render(request, self.template_name, context) def readFile

Class based views query: get objects referenced by another model

我只是一个虾纸丫 提交于 2019-12-13 04:03:33
问题 this question extends Django Pass Multiple Models to one Template In that I want to produce 1 template, that is my profile index page, so it will list all the objects created by the user specified in the url I want to query multiple models for one template, get the Profile in question and show all the oferto objects that was created by the attached profile views.py class ProfileIndex(ListView): context_object_name = 'account_list' template_name = 'profiles/account_index.html' queryset =

is it possible to use class based view instead of function based view wagtail?

本小妞迷上赌 提交于 2019-12-13 02:26:33
问题 i'm still struggling to integrate django wagtail to an existing project. i'm only using wagtail for my blog page. and i want to create a form to create new post for my blog from my wagtail page. the way i create this is using an routablepage. here's some of my code i'm using this as my reference models.py class BlogIndex(RoutablePageMixin, Page): ... @route(r'^send-post/$', name='send_posts') def submit(self, request): from .views import submit_news return submit_news(request, self) ... class

redirect user after update in class based view in django

我是研究僧i 提交于 2019-12-12 13:27:15
问题 I'm using Django 1.11. I'm using Class based view for update profile page, to updated auth user profile info. myapp/accounts/views.py class UpdateProfile(UpdateView): model = User fields = ['first_name', 'last_name'] template_name = 'accounts/update.html' def __init__(self, **kwargs): super().__init__(**kwargs) self.request = None def get_object(self, queryset=None): return self.request.user This works fine for updating profile. But after update, it gives error No URL to redirect to. Either

django how to get Response in class based view

為{幸葍}努か 提交于 2019-12-12 11:08:31
问题 now i have a class-based view. and i want to set cookie in this view,but i can get the response,but the response is returned in the get methond .so i can not set the cookie to response.so how to get Response in class based view class MyView(TemplateView): def get_context_data(self, **kwargs): context = super(UBaseTemplateView, self).get_context_data(**kwargs) #in here set cookie,but can get the response #response.set_cookie("success","success") return context 回答1: You cannot set_cookie on a

Type error with django class based view

旧城冷巷雨未停 提交于 2019-12-12 02:37:43
问题 I get this error TypeError at /author/list/4 super(type, obj): obj must be an instance or subtype of type Exception Location: /home/ronald/best/A2/0124/vort/larb/views.py in get_context_data, line 140 context = super(AuthorCreate, self).get_context_data(**kwargs) url.py url(r'^author/list/(?P<user_id>\d+)$', AuthorList.as_view(), name='author_list' ), views.py for listview class AuthorList(LoginRequiredMixin, ListView): template_name = 'authorList.html' queryset = Author.objects.all() def get

Dynamic queryset using request.POST data in class-based generic views

余生颓废 提交于 2019-12-11 08:45:30
问题 I'm interested in how to make dynamic queryset using request.POST query dict? When I did that: class ListCv(ListView): queryset = CV.objects.all() template_name = 'jobseek/applicants_resumes_list.html' paginate_by = 5 def get_context_data(self, **kwargs): context = super(ListCv, self).get_context_data(**kwargs) context['main_form'] = FilterCV(self.request.POST or None) return context def get_queryset(self): request = self.request main_form = FilterCV(request.POST or None) if main_form.is