django-views

RuntimeWarning for DateField in Django

北城以北 提交于 2020-01-06 07:56:19
问题 Hello i'm using dates for search queries. But i am getting runtime error. RuntimeWarning: DateTimeField Jobs.job_created_on received a naive datetime (2019-01-17 00:00:00) while time zone support is active. Views.py class JobListView(LoginRequiredMixin, generic.TemplateView): template_name = 'admin/jobs/job.html' def get(self, request, *args, **kwargs): context = super(JobListView, self).get_context_data(**kwargs) if 'status' in request.GET: form = JobSearchForm(request.GET) if form.is_valid(

Django FilteredSelectMultiple Right Half Does Not Render

筅森魡賤 提交于 2020-01-06 07:11:57
问题 I have the same problem as [@DHerls][1], but the given solution did not work for me. Django FilteredSelectMultiple not rendering on page Other similar questions with solutions I tried: Django FilteredSelectMultiple widget rendered with bootstrap Django admin's filter_horizontal not working Uncaught ReferenceError: django is not defined The problem is that only half of the FilteredSelectMultiple shows up: Things I have tried: syncdb checking that jQuery is running checked for jQuery imports

how to override returned serializer object that is returned with the response django rest framework serializer

。_饼干妹妹 提交于 2020-01-06 06:44:12
问题 I have a django rest framework project. I want to override the returned json object structure when a get request is made to display a specific way not similar to the database structure. My current return object is displayed like so: { "id": 9, "namespace": "steve", "path": "something/another", "value": "this is a value", "person": 1 }, { "id": 11, "namespace": "namespace1", "path": "path2", "value": "anyoher value", "person": 2 }, { "id": 12, "namespace": "namespace1", "path": "path3", "value

Assign Foreign Key Value after creating ( Logged In User )

喜你入骨 提交于 2020-01-06 06:32:09
问题 I have a createview using CBV class StudentCreate(LoginRequiredMixin, CreateView): login_url = '/signin/' model = Student fields = ['first_name', 'last_name' ] success_url = '/dashboard/' Respective models.py class Class_teacher(models.Model): first_name = models.CharField(max_length=200) last_name = models.CharField(max_length=200) standard = models.IntegerField() division = models.CharField(max_length=1) subject = models.CharField(max_length=200) email = models.CharField(max_length=30)

Django form not saving inputs- refreshes upon submission

两盒软妹~` 提交于 2020-01-06 06:04:27
问题 I am trying to create a website with two dropdown menus: Department and Course Number. The data for the dropdown menus comes from the "courses" table of my SQL database. Right now my website initializes properly and shows the correct options in the dropdown menus. However, when the user selects an option within the dropdown menus and submits their choices, the website reloads as a blank slate so their selections are not being saved or processed. The error lies somewhere in the CourseForm form

Ajax Call not being passed, POST.request shows as None

佐手、 提交于 2020-01-06 05:29:08
问题 I am having issues getting my POST request to capture the selected check boxes. It's been suggested to me to use Ajax so I did with the following: <script src="https://ajax.googleapis.com/ajax/libs/jquery/2.1.1/jquery.min.js"></script> <script> $(document).ready(function () { var SelectedItems = []; $('.checkbox').click(function () { var SelectedItems = $(this).val(); var index = SelectedItems.indexOf(SelectedItems); var url = window.location.href.split('?')[0]; if (index == -1) {

Django last page pagination redirect

假如想象 提交于 2020-01-06 03:57:06
问题 My problem is similar to this problem. The only difference is I use GCBV for my pagination. My view file is as follows: class ChatListView(ListView): model = Chat form_class = NewMessageForm template_name = 'chat.html' paginate_by = 5 queryset = model.objects.all() ###not needed def post(self, request, *args, **kwargs): form = self.form_class(request.POST) if form.is_valid(): form.save() return redirect('chat') <--- here return render(request, self.template_name, {'form': form}) def get

How to update a div with an image in Django?

≯℡__Kan透↙ 提交于 2020-01-06 02:29:05
问题 The following is a matplotlib code that generates a scatter plot in as the response. def plot(request): r = mlab.csv2rec('data.csv') fig = Figure(figsize=(6,6)) canvas = FigureCanvas(fig) ax = fig.add_subplot(111) ax.grid(True,linestyle='-',color='gray') ax.scatter(r.x,r.y); response=django.http.HttpResponse(content_type='image/png') canvas.print_png(response) return response I would like to update a div tag in the template using jquery ajax. Following is the jquery code that listens to a

Creating a drop-down menu of Member IDs

為{幸葍}努か 提交于 2020-01-05 23:56:18
问题 I have a model Member that includes a specification called member_id. class Member(models.Model): member_id = models.SlugField(max_length=10) name = models.CharField(max_length=200) gender = models.CharField(max_length=1, choices=GENDER_CHOICES) mobile = models.SlugField(max_length=20) def __str__(self): return self.name I want to create a drop-down menu of stored member ID's for the user to choose from in select_member.html . Right now, I have this in forms.py : (pretty sure it's wrong)

NoReverseMatch at / Reverse for 'password_change_done' with arguments '()' and keyword arguments '{}' not found. 0 pattern(s) tried: []

安稳与你 提交于 2020-01-05 08:34:06
问题 my views part: @login_required def password_change(request, template_name='register.html', password_change_form=PasswordChangeForm,): if post_change_redirect is None: post_change_redirect = reverse('student:login') else: post_change_redirect = reverse_url(post_change_redirect) if request.method == 'POST': form = password_change_form(user=request.user, data=request.POST) if form.is_valid(): form.save() update_session_auth_hash(request, form.user) return HttpResponseRedirect(post_change