Django 1.11 Annotating a Subquery Aggregate

This is a bleeding-edge feature that I'm currently skewered upon and quickly bleeding out. I want to annotate a subquery-aggregate onto an existing queryset. Doing this before 1.11 either meant...

Django 1.11 TypeError context must be a dict rather than Context

Just received the Sentry error TypeError context must be a dict rather than Context. on one of my forms. I know it has something to do with Django 1.11, but I am not sure what to change to fix...

Replicate part of production django database to local or staging

I have a Django website with 3 environments (Local, Staging, Production). Production contains some data that I don't want my developers to have access to (Personal data and financial data of...

How to annotate Django QuerySet with other object using Subquery

In Django version 1.11, Subquery expressions were added. I was hoping to use this feature to select a related model object based on some filters. This is an example from the documentation: from...

How annotate the Max value of two fields in a Django QuerySet

I have a model Client, how do i annotate then sort, the Max of its two fields: from django.db import models class Client(models.Model): uploaded_photo_at = models.DateTimeField() ...

AttributeError: 'NoneType' object has no attribute 'attname' (Django)

I have a fairly complex model for which the first call to MyModel.objects.create(**kwargs) fails with AttributeError: 'NoneType' object has no attribute 'attname' The stack trace dives down like...

What is "output_field" in django

Django doc says for aggregate functions: output_field - An optional argument that represents the model field of the return value So I expected that the code below returns...

Django delete cache with specific key_prefix

I'm using Django's per-view @cache_page decorator and have set a different key_prefix for each view. I've previously deleted the cache with: from django.core.cache import cache cache.clear() But...

lazy reference: doesn't provide model user?

Currently I'm using Django 1.11 and Python 3.6. I'm attempting to create a custom user model with a new application that authenticates with LDAP, but i'm greeted with the following error...

How to document function-based views parameters?

I'm developing a REST API with Django 1.11 and Django REST Framework 3.7. I installed Django REST Swagger 2.1 to generate the documentation. I'm using a function-based view like this: from...

ValueError: Unable to configure handler 'file': [Errno 13] Permission denied:

Using Django 1.11 and Python 2.7. I am unable to configure handler 'file' dues to permissions. Traceback is as follows: Traceback (most recent call last): File "manage.py", line 22, in...

Access the Django-Rest-Framework url do not load the styles file

I have a project with the settings.py: # -*- coding: utf-8 -*- """ Django settings for Qy project. Generated by 'django-admin startproject' using Django 1.11.5. For more information on this...

How to test auto_now_add in django

I have django 1.11 app and I want to write unit test for my solution. I want to test registration date feature. model.py: class User(models.Model): first_name =...

Django, ReactJS, Webpack hot reload

I've been trying to set up a React component inside Django with the help of Webpack 4. To get me starting I went through and read: Using Webpack transparently with Django + hot reloading React...

type="datetime-local" in Django form

I want to understand Django form. <div class="form-group"> <label for="deadline">Deadline</label> <input type="datetime-local" class="form-control"...

Docker SMTP Server for Django Container SMTP backend

I am looking to have one of my django docker containers setup a smtp backend so I can send input from a contact form to a gmail address as well as possibly send out an email when someone puts in...

Reference 'django.contrib.auth.urls' to custom specific templates

I wrote specific templates to deal with password reset and change, the file tree structures as: In [3]: !tree...

Issue Installing misaka in a Django project

I need to install misaka, but when I use pip install misaka I get an error that reads: Command "python setup.py egg_info" failed with error code 1 in...

Installing MySQL-python causes command 'clang' failed with exit status 1 on Mac OS 10.13.15

I have installed tools via xcode-select --install but still show the following error while doing pip install MySQL-python Building wheels for collected packages: MySQL-python Running setup.py...

Django conditional Subquery aggregate

An simplified example of my model structure would be class Corporation(models.Model): ... class Division(models.Model): corporation = models.ForeignKey(Corporation) class...

Change default value on field after migration in django

I have app in django 1.11 and I made migration. Now I have items in admin panel with 'John' in first_name and 'Smith' in last_name field. I would like to change it. Can I do this after made python...

Using Subquery to annotate a Count

Please help me I've been stuck on this for way too long :( What I want to do: I have these two models: class Specialization(models.Model): name = models.CharField("name", max_length=64) class...

how to compress the image before uploading to s3 in django?

I am working on an application where a user can upload an image. I want to reduce the size of the image in 200-500kb. This is my models.py file class Report_item(models.Model): owner =...

() missing 1 required positional argument: 'id'

I keep getting an error when trying to display individual items. This is my code, i hope its understandable. I'm using django 1.11 1.my urls page: urlpatterns = [ url(r'^$', views.home,...

Django: custom http header authentification

I want to create an authentication for my Django 1.11 project. A user will be authenticated if the request contains the header : X_USERNAME. I am working with generic views so I use...

How to use enums as a choice field in django model

I have a model class of which I want two fields to be a choice fields, so to populate those choices I am using an enum as listed below #models.py class Transaction(models.Model): ...

Using Multiple Databases with django

I have to use multiple databases in my project but there is a problem. Model can't see intended database accounts.db. when i go localhost:port/admin/app/accounts it says me no such table:...

Pipenv fails when installing packages for python 3.6

I am working on a project that requires pipenv, and python 3.6. When I run pipenv sync, it I get the error messages An error occurred while installing django-markdown-deux==1.0.5...

Django:[ODBC Driver 17 for SQL Server][SQL Server]Login failed for user 'test'. (18456)

I used Django to connect to SQL Server 2016 and I started executing Python3" manage.py Runserver 8000 Terminal prompt: django.db.utils .InterfaceError: ('28000', "[28000] [Microsoft][ODBC Driver...

djangosaml2 authenticates user but I get anonymous user in my view

I am using djangosaml2 to authenticate my users. I've been using it for a long time now with no problem. I am currently in the process of upgrading Python and Django to newer versions and the...