Default filter in Django admin

How can I change the default filter choice from 'ALL'? I have a field named as status which has three values: activate, pending and rejected. When I use list_filter in Django admin, the filter is...

Django templates: verbose version of a choice

I have a model: from django.db import models CHOICES = ( ('s', 'Glorious spam'), ('e', 'Fabulous eggs'), ) class MealOrder(models.Model): meal = models.CharField(max_length=8,...

Passing Python Data to JavaScript via Django

I'm using Django and Apache to serve webpages. My JavaScript code currently includes a data object with values to be displayed in various HTML widgets based on the user's selection from a menu of...

Setting DEBUG = False causes 500 Error

Once I change the DEBUG = False, my site will generate 500 (using wsgi & manage.py runserver), and there is no error info in Apache error log and it will run normally when I change debug to True...

How to properly use the "choices" field option in Django

I'm reading the tutorial here: https://docs.djangoproject.com/en/1.5/ref/models/fields/#choices and i'm trying to create a box where the user can select the month he was born in. What I tried was ...

Django: ImproperlyConfigured: The SECRET_KEY setting must not be empty

I am trying to set up multiple setting files (development, production, ..) that include some base settings. Cannot succeed though. When I try to run ./manage.py runserver I am getting the...

django translate model choices

I need translate a choices for a field on the model. I have something like this: from django.utils.translation import ugettext as _ from django.db import models class MyModel(models.Model): ...

elasticsearch exceptions ConnectionError

I am making a Django app. It uses Haystack with elasticsearch as backend. When I run ./manage.py rebuild_index I get this error: aborted.', error(61, 'Connection refused'))) caused by:...

OperationalError, no such column. Django

I am very new to django and was able to finish the tutorial on djangoproject.com without any errors. I am now going through the Django REST framework tutorial found at...

Django Rest Framework with ChoiceField

I have a few fields in my user model that are choice fields and am trying to figure out how to best implement that into Django Rest Framework. Below is some simplified code to show what I'm...

What is the best approach to keep many different django model type choices DRY?

I decoupled my system into many applications where each of those have many models from which many have This is the structure. ROOT core (for keeping generic stuff) decoupled app decoupled...

A node may not be made a child of any of its descendants in django mptt

here is the models.py class Category(MPTTModel): title = models.CharField(max_length =120) name = models.CharField(max_length=120) parent = models.ForeignKey('self' ,...

Is multi choice django admin filters possible..?

Suppose if there is a model named 'Cities' and at admin side there is a filter 'city_name' to filter model based on city names. By default django only allows to choose one city name from the...

Cannot resolve keyword 'username' into field. Choices are: city, id, phone, etc

I would like to ask for help in these issue. I do know that it seems similar to other questions regarding the same issue, but I did look around and there was nothing that actually could solve my...

Why choice field displays keys instead of values in django queryset?

I have a Choice Field in my models.py models.py STATUS = ( ('closed_issue', 'Closed Issue'), ('open_ssue', 'Open Issue'), ('pending', 'Pending'), ) class Issue(models.Model): name...

Django Admin Show / Hide Fields If Specific Value Is Selected In A Dropdown

In the Django admin, when the choice Custom is selected from a dropdown list, I want to display the inline start_date and end_date fields to allow the user to specify a specific start and end-date...

Issues printing Django email to console

I am not sure what is wrong with my logic, but when I submit a form, it renders the Httpresponse in the browser, but doesn't post the email to the console. I want the view function to be able to...

How to add Banned Users to table,and send details to user's email within Django Admin

I have a simple banning function that sets user active to false and a basic emailing function to send emails. The tables I am working with are User,Profile,Report & Banned_User Table. I am looking...

Searchable drop down for choice field in django admin

I have a choice field with lot's of data, I have created drop down at admin panel but I want to have a searchable drop down. class ItemForm(forms.ModelForm): def __init__(self, *args,...

Pylint "unresolved import" error in Visual Studio Code

I am using the following setup macOS v10.14 (Mojave) Python 3.7.1 Visual Studio Code 1.30 Pylint 2.2.2 Django 2.1.4 I want to use linting to make my life a bit easier in Visual Studio Code....

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): ...

get the actual value of the human-readable name from choices in django models

I made this model: name = models.CharField(max_length=3, choices=( ('sat', "Saturday"), ('sun', "Sunday"), ('mon', "Monday"), ('tue', "Tuesday"), ('wed',...

How to filter ModelAdmin autocomplete_fields results with the context of limit_choices_to

I have a situation where I wish to utilize Django's autocomplete admin widget, that respects a referencing models field limitation. For example I have the following Collection model that has the...

Django : AttributeError: type object 'Position' has no attribute '_meta'

I have a User model and a Position Model, Where Position and User model both has username and position name as unique key. I want to create a separate table(which will be a relation table) where I...

Django: check_password returns false, even if the password was saved as hash

I am using Django==2.1.5 My goal is a simple DRF based create user and login, but instead of login with username (and pw) i want to login with the email address+pw. Therefore I saved...

Accessing Django 3 TextChoices via an exposed API endpoint?

I am using Django 3.0.4 with Django REST Framework 3.11.0 where I have a models.py like: from django.db import models from model_utils.models import TimeStampedModel class...

How can save session of shopping cart data after logout, so the user can find them when login again in Django?

I am working on e-commerce website using Django, I'm working on the shopping cart it's implemented using sessions and it's currently working fine, except one problem when the authenticated user...

Is it possible to import in forms.py values from a view function Django? Is there another way to create functions in forms.py?

In my forms.py I have a section of code which gives me an error when I try to migrate for the first time. So I thought a good solution would be to change the location of the code. This is the...

Django 3.2 AttributeError: 'TextField' object has no attribute 'db_collation'

I've an existing project on Django 3.1 and I upgraded my project to Django 3.2. I created an app called payment on my project. But When I make migrations. It trow an error AttributeError:...

Django DatabaseError Invalid connector for timedelta

Previously, I did implement the ExpressionWrapper to create a custom filter, It's working fine in the postgresql, but when I did run test with sqlite3, then the error said...