django-class-based-views

Django class-based form with dropdowns populated with data from model / db

Django class-based form with dropdowns populated with data from model / db Question: This my Django code: forms.py from django import forms class MyForm(forms.Form): name = forms.CharField() location = forms.CharField() views.py class MyFormView(FormView): template_name = ‘form.html’ form_class = MyForm success_url = ‘home’ def get(self, request, *args, **kwargs): form = self.form_class return render(request, ‘form.html’, {‘form’: form}) …

Total answers: 1

Why individually rendered form fields not posting in Django?

Why individually rendered form fields not posting in Django? Question: I have a class based UpdateView that works fine if I render the form as {{ form.as_p }}. It updating the values, but looks bad. If I try to render the fields individually it does not updating the values. I can’t figure out how to …

Total answers: 1

Django CBV: How come my child method is not overriding my parent method?

Django CBV: How come my child method is not overriding my parent method? Question: I’m pretty new when it comes to python classes / django CBVs. I’m trying to have a method (print_test) from my child class override my parent class, but I can’t get it to work. What am I doing wrong? Below is …

Total answers: 1

User can't login because of "Invalid password format or unknown hashing algorithm."-Django

User can't login because of "Invalid password format or unknown hashing algorithm."-Django Question: I’m learning Django and tried to write my own custom user model. I’m not using DRF and serializers and stuffs I have no idea about 🙂 I am using createView to create users but I can’t login because "Invalid password." I checked …

Total answers: 1

reverse lazy error NoReverseMatch at django DeleteView

reverse lazy error NoReverseMatch at django DeleteView Question: I’m trying to return back to patient analyses list after deleting 1 analysis. But can’t manage proper success url So this is my model: class PatientAnalysis(models.Model): patient = models.ForeignKey(Patient, on_delete=models.CASCADE) analysis_date = models.DateTimeField(help_text = "Разделяйте даты точками! Используйте ‘/’ или ‘-‘") # analysis_type = models.IntegerField(choices = ANALYSIS_CHOICES) …

Total answers: 1

How to get query parameter through form-data postman in django

How to get query parameter through form-data postman in django Question: I have this viewset which should return certian results when i give query param week, month or year. class TotalOrdersViewset(viewsets.ModelViewSet): queryset = Order.objects.all() serializer_class = OrderSerializer def list(self, request, *args, **kwargs): try: type = request.data.get(‘type’) print(‘type= ‘+str(type)) if type is None: return Response({"success": False, …

Total answers: 1

Django DeleteView not make delete

Django DeleteView not make delete Question: I want to convert user deletion from FBV to CBV My FBV def delete_student(request, pk): student = get_object_or_404(Student, pk=pk) student.delete() return HttpResponseRedirect(reverse("students:get_students")) My CBV class DeleteStudentView(DeleteView): model = Student form_class = StudentForm template_name = "students/students_list.html" success_url = reverse_lazy("students:get_students") student_list.html <td><a type="button" class="btn btn-danger" href="{% url ‘students:delete_student’ student.pk %}">Delete</a> </td> …

Total answers: 1

Django: combine ListView and DeleteView to use with HTMX?

Django: combine ListView and DeleteView to use with HTMX? Question: I’m using Django with HTMX to manage a CRUD table in which I want to list and delete objects. For this, I have a ListView which displays a table (using django-tables) with pagination, sorting, and text search features. It works as expected with HTMX: for …

Total answers: 2

Detail view is not displaying content of models

Detail view is not displaying content of models Question: My detail View in Django, isn’t successfully displaying the content selected from the listviews. The following is my code. Models.py: from django.db import models from django.contrib.auth.models import User # Create your models here. class Post_Model(models.Model): Title = models.CharField(max_length=50) Author = models.ForeignKey(User, on_delete=models.CASCADE) Body = models.TextField() def …

Total answers: 1