Return all active comment in a post

i have this blog site,i want to return all acvtive comments associated to a post. def post_detail(request,year, month,day, post): post = get_object_or_404(Post,status=Post.Status.PUBLISHED,slug=post,publish__year=year,publish__month=month,publish__day=day) #list of active comments for this post comments = post.comments.filter(active=True) #form for users to comment form = CommentForm() #List of similar posts post_tags_ids = post.tags.values_list(‘id’,flat=True) similar_posts = Post.published.filter(tags__in=post_tags_ids).exclude(id=post.id) [:4] return render(request,’blog/post/detail.html’,{‘post’:post,’comments’:comments,’form’:form}) Its returning… Read More Return all active comment in a post

How i get the value from a dictionary if the key from all keys are the same?

I wanna from a dictionary all values but i have for each value the same key. It is possible that i can get the values in a separately empty list? dic = QuesModel.objects.values("ans").distinct() print(dic) # i get: """<QuerySet [{‘ans’: ‘antwort1’}, {‘ans’: ‘answer2’}, {‘ans’: ‘besitzt als Modelle elemente verschiedene Ereignistypen.’}, {‘ans’: ‘als Nachrichten und Datenobjekte e… Read More How i get the value from a dictionary if the key from all keys are the same?

Django queryset to list of ids with integer values

I need to retrieve IDs from multiple queries and add them into a list. products = Product.objects.filter(category="Apple").values_list("product_id", flat=True) reviewed = Reviews.objects.filter(category="Apple").values_list("product_id", flat=True) selected_ids = [10,20,30] Then I tried all_products = selected_ids + products + reviewed This raised error as list cannot be added to queryset. so, I tried, all_product_ids = selected_ids + list(products) + list(reviewed)… Read More Django queryset to list of ids with integer values

__init__() got multiple values for argument 'user'

I have a form, model and view and trying to show ModelChoiceField with filters I wrote an init in my forms.py but when im trying to submit my form on html page i got an error: "__init__() got multiple values for argument ‘user’ " forms.py class WorkLogForm(forms.ModelForm): worklog_date = forms.DateField(label=’Дата’, widget=forms.DateInput( attrs={‘class’: ‘form-control’, ‘placeholder’: ‘Введите… Read More __init__() got multiple values for argument 'user'

How to call a function in django view.py

I need to call the function get_context_data in my VacanciesView. Code views.py: def VacanciesView(request): navigate_results = Navigate.objects.all() context_vac = { ‘navigate_results’: navigate_results} get_context_data(self, **kwargs) return render(request, ‘main/vacancies.html’, context_vac) def get_context_data(self, **kwargs): context = super(VacanciesView, self).get_context_data(**kwargs) context[‘vacancies’] = sorted(get_vacancies(), key=lambda item: item["published_at"][:10]) return context I try to do it by get_context_data(self, **kwargs), but it takes: name… Read More How to call a function in django view.py