Django community: RSS
This page, updated regularly, aggregates Django Q&A from the Django community.
-
While deleting : ValueError: "<User: Test USER (testuser)>" needs to have a value for field "id" before this many-to-many relationship can be used
I'm pretty sure people will say this question already has answers but I couldn't find any. In other questions, the problem appears when creating objects with many-to-many relations. In my case, it happens when I try to delete a record.... Eh ?! I have the User model and the Group (from django.contrib.auth.models import Group) with a standard many-to-many relation between them (django standard). Everything was working fine until I use the depth Meta attribute in the serializers (which is very convenient by the way !). My User serializer : from rest_framework import serializers from ..models.base_user import User class BaseUserSerializer(serializers.ModelSerializer): class Meta: model = User depth = 1 fields = ( 'id', 'username', 'email', 'first_name', 'last_name', 'is_active', 'groups', ) My Group serializer : from django.contrib.auth.models import Group from rest_framework import serializers class BaseGroupSerializer(serializers.ModelSerializer): class Meta: model = Group depth = 1 fields = ( 'id', 'name', 'user_set', ) def to_representation(self, instance): response = super().to_representation(instance) # By using the 'depth' Meta attribute, the nested User records were serialized # with their password. By doing this, we remove the 'password' field from the # representation of the Groups and their nested Users. for user in response.get("user_set"): user.pop("password", None) return response My API function … -
Extracting data with celery and beautifulsoup
I'm extracting data of articles in a website and pars them in my db in a django project using celery and bs4.Here is article model: articles/model.py from django.db import models from conduit.apps.core.models import TimestampedModel class Article(TimestampedModel): slug = models.SlugField(db_index=True, max_length=255, unique=True) title = models.CharField(db_index=True, max_length=255) description = models.TextField() body = models.TextField() # Every article must have an author. This will answer questions like "Who # gets credit for writing this article?" and "Who can edit this article?". # Unlike the `User` <-> `Profile` relationship, this is a simple foreign # key (or one-to-many) relationship. In this case, one `Profile` can have # many `Article`s. author = models.ForeignKey( 'profiles.Profile', on_delete=models.CASCADE, related_name='articles' ) tags = models.ManyToManyField( 'articles.Tag', related_name='articles' ) def __str__(self): return self.title class Comment(TimestampedModel): body = models.TextField() article = models.ForeignKey( 'articles.Article', related_name='comments', on_delete=models.CASCADE ) author = models.ForeignKey( 'profiles.Profile', related_name='comments', on_delete=models.CASCADE ) class Tag(TimestampedModel): tag = models.CharField(max_length=255) slug = models.SlugField(db_index=True, unique=True) def __str__(self): return self.tag profile/model.py from django.db import models from conduit.apps.core.models import TimestampedModel class MyUser(models.Model): username = models.CharField(max_length=255) class Profile(TimestampedModel): user = models.ForeignKey( MyUser, on_delete=models.CASCADE ) bio = models.TextField(blank=True) image = models.URLField(blank=True) follows = models.ManyToManyField( 'self', related_name='followed_by', symmetrical=False ) favorites = models.ManyToManyField( 'articles.Article', related_name='favorited_by' ) def __str__(self): return self.user.username def follow(self, … -
How to generate qr code with logo in Python
I have a project to generate qr code with logo in center of qr code. How I can make it like this. enter image description here now I'm use django-qr-code to generate text qr code but I need qr code with logo in center. -
How to use keyTextTransform() for nested json?
My model has a json field. I can access jsonfield['key1'] with the following query from django.contrib.postgres.fields.jsonb import KeyTextTransform MyModel.objects.annotate(val=KeyTextTransform('key1', 'jsonfield')).order_by('val') But how can I access a key like jsonfield['key1']['key2'] or even more nested ones? -
Background Function in Django on Button Click
I'm trying to create an app that has a button on the frontend dashboard for starting execution of a function and stoping execution of a function. So is there any way to do the same in Django? For Ex. I have a function to add something to the database. When I press the start button it should start the execution of that function in the background which should not affect the site. And it should print or save the log to the database after completion of function execution each time. The function should run repeatedly. And the function execution should stop when I press the stop button from the dashboard. -
Problems when laoding some csv data to a django application because gettext
I hope someone could help with this, or maybe someone had the same problem. I am trying to import some csv by using this command to a database, the csv needs to be pair to a mapping file to create relationship, followed the instructions for the web-app being used. python manage.py packages -o import_business_data -s /path/to/the/file.csv -c /path/to/the/file.mapping -ow 'overwrite' -bulk After run the command in my local machine it successfully load all the data, but when doing the same in the production instance I get these messages so I can guess the command line run is correct but something is configured wrong in the instance, the error is related with the translation you can see it below: Traceback (most recent call last): File "manage.py", line 28, in <module> execute_from_command_line(sys.argv) File "/usr/local/lib/python2.7/dist-packages/django/core/management/__init__.py", line 364, in execute_from_command_line utility.execute() File "/usr/local/lib/python2.7/dist-packages/django/core/management/__init__.py", line 308, in execute settings.INSTALLED_APPS File "/usr/local/lib/python2.7/dist-packages/django/conf/__init__.py", line 56, in __getattr__ self._setup(name) File "/usr/local/lib/python2.7/dist-packages/django/conf/__init__.py", line 41, in _setup self._wrapped = Settings(settings_module) File "/usr/local/lib/python2.7/dist-packages/django/conf/__init__.py", line 110, in __init__ mod = importlib.import_module(self.SETTINGS_MODULE) File "/usr/lib/python2.7/importlib/__init__.py", line 37, in import_module __import__(name) File "/opt/maindb-app/eamena-main-app/eamena/eamena/settings.py", line 225, in <module> ('NAME.E41', _('Resource Names')), File "/usr/local/lib/python2.7/dist-packages/django/utils/translation/__init__.py", line 89, in ugettext return _trans.ugettext(message) File "/usr/local/lib/python2.7/dist-packages/django/utils/translation/trans_real.py", line 345, in ugettext return … -
Javascript: Call function every time browser loading is cancelled
I hope you can help me. I need to call a javascript function every time the browser loading is cancelled. I think I may use window.stop() but I don't know how exactly read when the window stopped loading. What I'm trying to achieve is this: Do something when I click browser's cancell button I can provide more information about my project, I'm developing a web app with Django (Python) to execute a Fbprophet model. But I need to achieve this with Javascript. And what I want to do with the function is hide the loading bar you can see in the picture. I hope someone knows how to do it. Thanks!!! -
PasswordResetConfirmView return 200 success reponse but password is not changed in django
I just implemented reset password in my app using django.contrib.auth.views. I'm on the half way now but there is one problem with PasswordResetConfirmView. When I requested for password reset by entering the email, my app sent a link to the email that i just input. After I clicked on that link, it redirected me to a view which is PasswordResetConfirmView. After entered the new password, new confirm password, and submit the form it returns 200 success response without redirecting me to the PasswordResetCompleteView and also the password is not changed yet. I think i miss something but can't figure it out so I'm here asking for help. urls.py from django.contrib.auth import views as auth_views urlpatterns = [ path('reset-pasword/', auth_views.PasswordResetView.as_view(template_name="password_reset/password_reset.html"), name="password_reset"), path('reset-password-done/', auth_views.PasswordResetDoneView.as_view(template_name="password_reset/password_reset_done.html"), name="password_reset_done"), path('reset-password-confirm/<uidb64>/<token>/', auth_views.PasswordResetConfirmView.as_view(template_name="password_reset/password_reset_confirm.html"), name="password_reset_confirm"), path('reset-password-complete/', auth_views.PasswordResetCompleteView.as_view(template_name="password_reset/password_reset_complete.html"), name="password_reset_complete"), ] [Updated] here is the response "POST /user-account/reset-password-confirm/NA/ah5gne-48bf0be46e301fc88c52e0fb060b0f0b/ HTTP/1.1" 200 16764 Everything works perfectly fine except password is not changed. -
how to add class to django ModelForms file field
I want to add class for my file field as other elements(while I can't use attrs={"rows": "1", "class": "form-control"} I've no idea how to go on), couldn't find any guides about that every where they applied that on other fields. forms.py from django import forms from .models import MedicalRecords class UpdateMedicalRecordForm(forms.ModelForm): class Meta: model = MedicalRecords fields = ("title", "file", "doctor") widgets = { "title": forms.Textarea(attrs={"rows": "", "class": "form-control"}), "file": ?? (how to add class as above), } -
Looking for a DRY method to link to a sub navigation in Django
I'm currently using Django 3.1 and Python 3.7. I've been looking for a more efficient way to access the sub-navigation. Here is the background of the project. This is a social media site with individual profiles for each individual. Each profile contains a dynamic sub-navigation such as post, reviews and comments. All 3 don't necessarily appear. They only appear when they already have a particular post, review or comment. Because of this I created a category list to dynamically appear if it's available. This is done via a For Loop within the template. Since this is an object model, I want to be able to create an absolute url. The challenge is, when clicking the sub-navigation such as Post, Review or Comment, this should go to the Profile's Post, Review or Comment Page. Currently, this is my urls: urlpatterns = [ path('<slug:profile_slug>/', profileView, name="profile"), path('<slug:profile_slug>/<slug:post_slug>/', profilePostView, name="profile_posts"), ] This is currently part of my template. It is the sub-navigation part of the page. {% for category in categories_list %} <li class="nav-item"> <a class="nav-link active" href="#">{{ category.name }}</a> </li> {% endfor %} So I want to be able to go to the category via the corresponding link. I want to avoid … -
Django inconsistent queryset results
I'm noticing some inconsistency after some bulk additions were made to the dataset. Beforehand, the IDs from Metadata always returned querysets. Now, half of the IDs in Metadata are returning a queryset, while the new batch are always returning empty querysets. models.py: class Metadata(models.Model): strain_id = models.CharField(max_length=255, blank=True) psql: (note single quotes added around IDs 2290 and 1002, not present in Django .query statements) ## Old batch: pg=# SELECT DISTINCT ON (U0."strain_id") U0."id" FROM "chat_metadata" U0 WHERE U0."strain_id" IN ('2290') ORDER BY U0."strain_id" ASC; id ------ 1457 (1 row) ## New batch (working here???): pg=# SELECT DISTINCT ON (U0."strain_id") U0."id" FROM "chat_metadata" U0 WHERE U0."strain_id" IN ('1002') ORDER BY U0."strain_id" ASC; id ------ 1474 (1 row) However, the result of .queryset.query is SELECT DISTINCT ON (U0."strain_id") U0."id" FROM "chat_metadata" U0 WHERE U0."strain_id" IN (2290) ORDER BY U0."strain_id" ASC. This magically works when run inside Django and returns a valid queryset. However, when run from psql, the following occurs: pg=# SELECT DISTINCT ON (U0."strain_id") U0."id" FROM "chat_metadata" U0 WHERE U0."strain_id" IN (2290) ORDER BY U0."strain_id" ASC; ERROR: operator does not exist: character varying = integer LINE 1: ..."id" FROM "chat_metadata" U0 WHERE U0."strain_id" IN (2290) ... ^ HINT: No operator matches … -
What's the difference between a tuple and list in the python which one is more efficient
In my one of the interview the interview ask me about the tuple and the list in python. And ask which is more efficient in case of finding a element on both . -
Use django query __isnull with field name containing spaces or hyphens
I looked up how to filter a models.object-list with 'varname__isnull=True', but didn't find a solution for the case that a name containing a space-character was given: In my views.py I have the following function: def currenttodos(request): todos = Todo.objects.filter(user=request.user, time_completed__isnull=True) return render(request, 'todo/currenttodos.html', {'todos': todos}) The model Todo in the models.py - file comprises the following field: time_completed = models.DateTimeField(null=True, blank=True) This way it works, but actually I wanted to call the time_completed - field differently, for example "Completion time" using the name-parameter: time_completed = models.DateTimeField(null=True, blank=True, name="Completion time") Now, the problem is that I can't use the __isnull - parameter since the name contains a space. All of the following examples don't work: todos = Todo.objects.filter(user=request.user, Completion time__isnull=True) todos = Todo.objects.filter(user=request.user, "Completion time"__isnull=True) todos = Todo.objects.filter(user=request.user, "Completion time"=None) etc. How can I make this work for names containing spaces or hyphens? -
Error message: Employee matching query does not exist
I have model Employee and same table in my local database. I need to have the possibility to edit any record and save it locally. When I have something in the webflow_id field I got this error when I tried to select the edit option: Employee matching query does not exist. When I tried to edit record without this webflow_id it doesn't change, but creates a new record. my views.py: def staff_edit(request, webflow_id): #employees = Employee.objects.all() #print(employees) # this gave me QuerySet of the records from the database if request.method == 'GET': if webflow_id == 0: form = EmployeeEditForm() else: #employees = Employee.objects.get(pk=webflow_id) employees = Employee.objects.get(pk=webflow_id) form = EmployeeEditForm(instance=employees) return render(request, 'staffedit.html', {'form': form}) else: if webflow_id == 0: form = EmployeeEditForm(request.POST) else: employees = Employee.objects.get(pk=webflow_id) form = EmployeeEditForm(request.POST, instance=employees) if form.is_valid(): form.save() return redirect('feedback:staff') context = {'form': form} #when the form is invalid return render(request, 'staffedit.html', context) models.py: class Employee(models.Model): webflow_id = models.CharField(max_length=100, default=True) first_name = models.CharField(max_length=100) last_name = models.CharField(max_length=100, default=True) email = models.EmailField(max_length=100) user_type = models.CharField(max_length=100) status = models.CharField(max_length=100, default=True) roles = models.ManyToManyField('Role', through='EmployeeRole') def __str__(self): return self.webflow_id + " " + self.email + " " + self.first_name + " " + self.last_name this is my general html … -
Rpy2 in python 3.6 working sometimes and sometimes not
i am using rpy2 to run my R script in django project where python is 3.6 and i came across a weird error.sometimes my whole code is working and sometimes r object is NULL . > path2script = os.path.join(settings.BASE_DIR, 'r_scripts', 'script.R') > ro.globalenv['args'] = ro.vectors.StrVector([txt_path]) > obj = ro.r.source(path2script) > returnarray = np.array(obj,dtype="object") exactly at the third line python returns me an error which says "TypeError: 'NULLType' object is not callable" and again after sometime the same code works without any error.How robject is getting NULL . Any help would be appreciated. -
The text printed out for the Question class is not the text that I expect
from django.db import models from django.utils import timezone import datetime class Question(models.Model): question_text = models.CharField(max_length=200) pub_date = models.DateTimeField('date published') def __str__(self): return self.question_text def was_published_recently(self): return self.pub_date >= timezone.now() - datetime.timedelta(days=1) class Choice(models.Model): question = models.ForeignKey(Question, on_delete=models.CASCADE) choice_text = models.CharField(max_length=200) votes = models.IntegerField(default=0) def __str__(self): return self.choice_text When I follow the tutorial for Django, I found a problem that when I run Question.objects.all(), it then only printed out the class name instead of the text that I had already set. May I ask what is the method that I could print the text out instead of only printing the class name every time? -
Simple caching mechanism for Django manager functions
I have some Django simple manager functions where I'd like to cache the response (using Memcached), and invalidate these on model save/delete. I thought there'd be a standard solution for this in the Django community, but I can't find one, so would like to check I'm not reinventing the wheel. Here's an example with a possible solution using django-cache-memoize from cache_memoize import cache_memoize from django.utils.decorators import method_decorator from django.db.models.signals import post_save, post_delete from django.conf import settings class MyModel(Model): name = models.CharField() is_live = models.BooleanField() objects = MyModelManager() class MyModelManager(Manager): @method_decorator(cache_memoize(settings.CACHE_TTL, prefix='_get_live')) def _get_live(self): return super().get_queryset().filter(is_live=True) def example_queryset(): return self._get_live() # Cache invalidation def clear_manager_cache(sender, instance, *args, **kwargs): MyModel.objects._get_live.invalidate(MyModel) post_save.connect(clear_manager_cache, sender=MyModel, weak=False) post_delete.connect(clear_manager_cache, sender=MyModel, weak=False) This seems to work, but strikes me as quite a lot of boilerplate for something that's a pretty standard Django pattern/use-case. Are there any simpler solutions out there to achieve a similar thing? -
Django quickbook-desktop web connector integration
i am new to quickbooks and i am using django-quickbooks module to integrate with django and quickbooks desktop. So i was following this documentation https://github.com/weltlink/django-quickbooks and i have completed all the steps given now i am confused that what is the next part? webapp is still not connected with webconnector. How to include/implement functions like:- Soap session handling for 8 basic quickbooks web connector operations: authenticate() clientVersion() closeConnection() connectionError() getLastError() getServerVersion() receiveResponseXML() sendRequestXML() -
How to filter out Friends of user in search users function Django
I'm trying to filter out the friends of a user and also the current logged in user from a "search_users" function, I've tried using exclude() but keep getting an error I'm not sure whats wrong. I also wanted to add a "add friend" button next to the users, which I think I've done correctly on 'search_users.html. Error views.py @login_required def search_users(request): query = request.GET.get('q') object_list = User.objects.filter(username__icontains=query).exclude(friends=request.user.profile.friends.all()) context ={ 'users': object_list } return render(request, "users/search_users.html", context) search_users.html {% extends "feed/layout.html" %} {% load static %} {% block searchform %} <form class="form-inline my-2 my-lg-0 ml-5" action="{% url 'search_users' %}" method="get" > <input name="q" type="text" placeholder="Search users.." /> <button class="btn btn-success my-2 my-sm-0 ml-10" type="submit"> Search </button> </form> {% endblock searchform %} {% block content %} <div class="container"> <div class="row"> <div class="col-md-8"> {% if not users %} <br /><br /> <h2><i>No such users found!</i></h2> {% else %} <div class="card card-signin my-5"> <div class="card-body"> {% for user_p in users %} <a href="{{ user_p.profile.get_absolute_url }}" ><img src="{{ user_p.profile.image.url }}" class="rounded mr-2" width="40" height="40" alt="" /></a> <a class="text-dark" href="{{ user_p.profile.get_absolute_url }}" ><b>{{ user_p }}</b></a > <small class="float-right"> <a class="btn btn-primary mr-2" href="/users/friend-request/send/{{ user_p.username }}" >Add Friend</a> </small> <br/><br /> {% endfor %} </div> </div> {% … -
Django Rest Framework custom POST URL endpoints with defined parameter
previously in Django 1.11, I'ved defined Django REST API in this way: in url.py url(r'^api/test_token$', api.test_token, name='test_token'), in api.py @api_view(['POST']) def test_token(request): # ----- YAML below for Swagger ----- """ description: test_token parameters: - name: token type: string required: true location: form """ token = request.POST['token'] return Response("test_token success", status=status.HTTP_200_OK) Now that I am migrating to Django 3.1.5, I'd like to know how the above can be achieved in the same way with Django Rest Framework (DRF). In the above particular case, it is POST API that takes in one parameter. (also if possible generate API documentation like swagger/redoc) -
Filter objects in a queryset by a boolean condition
I would like to filter objects in a Queryset according to a Boolean condition and can’t figure out the best way to do it. At the moment I have two models: class Language(models.Model): langcode = models.CharField(max_length=3, unique=True) Translated = models.BooleanField(default=False) class Countries(models.Model): countrycode = models.CharField(max_length=3, unique=True) spoken_languages = models.ManyToManyField(Language) Continent = models.CharField(max_length=50) This represents a table of unique languages and a table of unique countries. Many countries speak many different languages but not every language has been translated yet. What I would like now is a Countries queryset where only translated languages appear in the spoken language section. My ideas were to make a Countries model property “translated_languages” that updates automatically when a languages Translated is turned True. But I can't figure out how to make it behave like I want it too (auto update when language gets translated etc.). Second attempt was to filter it on a view level but here I failed again because I couldn’t figure out how to filter it for each Country individually and store it. Then I tried it on a template level but filter doesn’t work there. In the end, I would like to use the object in two template for loops: {% … -
should i use free version of mysql? [closed]
hi, i am trying to build a blog application in which users can post there images and anyone can view(instagram clone). just imagine on huge scale if everyday many users upload their photos and data , will the database get slow or lead to data failure, if so for huge application can we use standard free mysql or in this case should i purchase paid mysql in short if application is huge and active 24?7 can database handle this much of traffic in your oppinion if i am building huge application , interms of datastorage and transfer what should i do using django as framework and rest common languages -
Django Login Page Location
I am trying to include a simple Login page into my Django project, following these steps: https://learndjango.com/tutorials/django-login-and-logout-tutorial At some point I think I am mistaken when I locate the registration folder, which is inside the templates one. My project structure is now as follows: project project ... application ... templates registration login.html But it raises me an error when I try to load http://127.0.0.1:8000/accounts/login Using the URLconf defined in project.urls, Django tried these URL patterns, in this order: 1. application/ 2. admin/ The current path, accounts/login, didn't match any of these. It also raises me the same error when I locate the registration folder inside the application/templates one (which is what I've been using for other html files). In addition, there is a point in the tutorial saying that the URLs provided by auth are: accounts/login/ [name='login'] accounts/logout/ [name='logout'] accounts/password_change/ [name='password_change'] accounts/password_change/done/ [name='password_change_done'] accounts/password_reset/ [name='password_reset'] accounts/password_reset/done/ [name='password_reset_done'] accounts/reset/<uidb64>/<token>/ [name='password_reset_confirm'] accounts/reset/done/ [name='password_reset_complete'] But it seems Django is just looking at 1. application/ and 2. admin/ Any idea about why this is happening? -
I am trying to download Django-heroku. But I am getting this Error: pg_config executable not found., how to solve it?
(myvenv) (base) siddhants-MacBook-Air:personal-project siddhantbhargava$ pip install django-heroku Collecting django-heroku Using cached django_heroku-0.3.1-py2.py3-none-any.whl (6.2 kB) Requirement already satisfied: dj-database-url>=0.5.0 in ./myvenv/lib/python3.8/site-packages (from django-heroku) (0.5.0) Requirement already satisfied: whitenoise in ./myvenv/lib/python3.8/site-packages (from django-heroku) (5.2.0) Requirement already satisfied: django in ./myvenv/lib/python3.8/site-packages (from django-heroku) (2.2.17) Requirement already satisfied: pytz in ./myvenv/lib/python3.8/site-packages (from django->django-heroku) (2020.5) Requirement already satisfied: sqlparse>=0.2.2 in ./myvenv/lib/python3.8/site-packages (from django->django-heroku) (0.4.1) Collecting psycopg2 Using cached psycopg2-2.8.6.tar.gz (383 kB) ERROR: Command errored out with exit status 1: command: /Users/siddhantbhargava/personal-project/myvenv/bin/python -c 'import sys, setuptools, tokenize; sys.argv[0] = '"'"'/private/var/folders/2n/rlv6c5zn6cbggrbcw65fvbz40000gn/T/pip-install-8opynhmw/psycopg2_6f717d71852848bb86def529de299ce9/setup.py'"'"'; file='"'"'/private/var/folders/2n/rlv6c5zn6cbggrbcw65fvbz40000gn/T/pip-install-8opynhmw/psycopg2_6f717d71852848bb86def529de299ce9/setup.py'"'"';f=getattr(tokenize, '"'"'open'"'"', open)(file);code=f.read().replace('"'"'\r\n'"'"', '"'"'\n'"'"');f.close();exec(compile(code, file, '"'"'exec'"'"'))' egg_info --egg-base /private/var/folders/2n/rlv6c5zn6cbggrbcw65fvbz40000gn/T/pip-pip-egg-info-q4d5yztd cwd: /private/var/folders/2n/rlv6c5zn6cbggrbcw65fvbz40000gn/T/pip-install-8opynhmw/psycopg2_6f717d71852848bb86def529de299ce9/ Complete output (23 lines): running egg_info creating /private/var/folders/2n/rlv6c5zn6cbggrbcw65fvbz40000gn/T/pip-pip-egg-info-q4d5yztd/psycopg2.egg-info writing /private/var/folders/2n/rlv6c5zn6cbggrbcw65fvbz40000gn/T/pip-pip-egg-info-q4d5yztd/psycopg2.egg-info/PKG-INFO writing dependency_links to /private/var/folders/2n/rlv6c5zn6cbggrbcw65fvbz40000gn/T/pip-pip-egg-info-q4d5yztd/psycopg2.egg-info/dependency_links.txt writing top-level names to /private/var/folders/2n/rlv6c5zn6cbggrbcw65fvbz40000gn/T/pip-pip-egg-info-q4d5yztd/psycopg2.egg-info/top_level.txt writing manifest file '/private/var/folders/2n/rlv6c5zn6cbggrbcw65fvbz40000gn/T/pip-pip-egg-info-q4d5yztd/psycopg2.egg-info/SOURCES.txt' Error: pg_config executable not found. pg_config is required to build psycopg2 from source. Please add the directory containing pg_config to the $PATH or specify the full executable path with the option: python setup.py build_ext --pg-config /path/to/pg_config build ... or with the pg_config option in 'setup.cfg'. If you prefer to avoid building psycopg2 from source, please install the PyPI 'psycopg2-binary' package instead. For further information please check the 'doc/src/install.rst' file (also at <https://www.psycopg.org/docs/install.html>). ---------------------------------------- ERROR: Command errored out with exit status 1: python … -
Using annotate() on top of django filters
Is it possible to use annotate on top of Django filters? I'm not referring to the filter() in the django documentation but django-filters. Something like this gave me an attributeerror to say that the filter does not have the attribute annotate post = postFilter(request.GET, queryset=BlogPost.objects.exclude((Q(author_id__in=request.user.blocked_users.all()) | Q(author = request.user))).order_by('date_updated')).annotate(user_has_interest=Case(When(interest__user=request.user, then=Value(True)), default=False, output_field=BooleanField()))