Django community: RSS
This page, updated regularly, aggregates Django Q&A from the Django community.
-
Django, Mod_WSGI and Apache2.4 return 403 with Require all granted
I'm sorry I but new to server config, I had been trying previous month to get my django project run live on WWW. I had run out ideas on solving error 403; I search stack overflow; Apache2 mod_wsgi 403 forbidden error Django + wsgi = Forbidden 403 Django with mod_wsgi returns 403 error 403 Forbidden error with Django and mod_wsgi Django, mod_wsgi and apache2.4 = problems Django + mod_wsgi + Apache = 403 Forbidden But only answer I get is just write this codes; <Directory C:\Frontier_Website\FrounterWebApp\FronterWeb> <Files wsgi.py> Require all granted </Files> </Directory> to allow access, which still having error 403. I try using virtual env but I had config issue and lead to error 500 This are my codes: httpd Apache code for only mod_wsgi area ##setting of the Apache httpd config for mod_wsgi LoadModule wsgi_module "C:\users\user\appdata\local\programs\python\python37\lib\site-packages/mod_wsgi/server/mod_wsgi.cp37-win_amd64.pyd" WSGIScriptAlias / "C:\Frontier_Website\FrounterWebApp\FrounterWeb\wsgi.py" WSGIPythonPath "C:\Frontier_Website\FrontierWebApp\zigview" WSGIPythonHome "C:\Users\user\AppData\Local\Programs\Python\Python37" <Directory C:\Frontier_Website\FrounterWebApp\zigview\static> Require all granted </Directory> <Directory C:\Frontier_Website\FrounterWebApp\FronterWeb> <Files wsgi.py> Require all granted </Files> </Directory> wsgi.py codes; #wsgi in my poject import os from django.core.wsgi import get_wsgi_application os.environ.setdefault('DJANGO_SETTINGS_MODULE', 'FrounterWeb.settings') application = get_wsgi_application() If you could help I really apprentice it because I ask multiplier time on this subject on different forms, and reply. -
Profile Image ruining elements on entire page
I'm building a blog as my first project in web dev. I've encountered an issue where, when I add a profile image next to the user's name, chaos ensues. Running this same code on here seems to show it working correctly, however it is not. Any ideas? Your help is greatly appreciated, thank you. How the formatting should be Chaos body { background: url('redpattern.jpg') no-repeat center fixed; background-size: auto; /* color: #333333;*/ margin-top: 5rem; } #ruleslist { padding-top: 25px; color: #ffffff; font-size: 2em; } #holly { position: absolute; height: 600px; width: 90%; } h1, h2, h3, h4, h5, h6 { color: #000000; } #sidebar { color: #000000; } ul { margin: 0; } bg-steel { color: #b52525; } .site-header .navbar-nav .nav-link { color: #ffffff; } .site-header .navbar-nav .nav-link:hover { color: #208ee8; } .site-header .navbar-nav .nav-link.active { font-weight: 5500; } .content-section { background: #ffffff; padding: 10px 20px; border: 1px solid #dddddd; border-radius: 3px; margin-bottom: 20px; } .article-title { color: #444444; } a.article-title:hover { color: #418ac9; text-decoration: none; } .article-content { white-space: pre-line; } .article-img { height: 65px; width: 65px; margin-right: 16px; } .article-metadata { padding-bottom: 1px; margin-bottom: 5px; border-bottom: 1px solid #e3e3e3 } .article-metadata a:hover { color: #333; text-decoration: none; } … -
First day in calendar is monday
I'm following this tutorial to implement a calendar on my site. https://www.huiwenteo.com/normal/2018/07/24/django-calendar.html Currently, Monday is the first day of the week in the calendar. Can you see any changes that I can make to the following code to make Sunday the first day of the week? class Calendar(HTMLCalendar): def __init__(self, year=None, month=None): self.year = year self.month = month super(Calendar, self).__init__() # formats a day as a td # filter events by day def formatday(self, day, events): events_per_day = events.filter(start_time__day=day) d = '' for event in events_per_day: d += f'<li> {event.title} </li>' if day != 0: return f"<td><span class='date'>{day}</span><ul> {d} </ul></td>" return '<td></td>' # formats a week as a tr def formatweek(self, theweek, events): week = '' for d, weekday in theweek: week += self.formatday(d, events) return f'<tr> {week} </tr>' # formats a month as a table # filter events by year and month def formatmonth(self, withyear=True): events = Event.objects.filter(start_time__year=self.year, start_time__month=self.month) cal = f'<table border="0" cellpadding="0" cellspacing="0" class="calendar">\n' cal += f'{self.formatmonthname(self.year, self.month, withyear=withyear)}\n' cal += f'{self.formatweekheader()}\n' for week in self.monthdays2calendar(self.year, self.month): cal += f'{self.formatweek(week, events)}\n' return cal Thanks! -
KeyError at /login/ 'is_login' Request Method: django
enter image description here I am coding web with django. I can not use session. I wanna check login use session def user_login(request): if request.session['is_login'] == True: return HttpResponseRedirect('/home') else: next = request.POST.get('next', request.GET.get('next', '')) if request.method == "POST": username1 = request.POST.get('username') password1 = request.POST.get('password') user = authenticate(username=username1, password=password1) if user is not None: if user.is_active: login(request, user) if next: request.session['is_login'] = True return HttpResponseRedirect(next) return HttpResponseRedirect('/home') else: return HttpResponse('Inactive user') else: return HttpResponseRedirect(LOGIN_URL) return render(request, "pages/login.html") How to fix -
Unable to filter using a queryset from the DB to show filtered options in form or filter plus check before saving
This is my django model: class Schedule(models.Model): instructor = models.ForeignKey(settings.AUTH_USER_MODEL, unique=False, on_delete=models.PROTECT, to_field='username') start_date = models.DateTimeField('Start Date', default=None) end_date = models.DateTimeField('End Date', blank=True, null=True) room_number = models.ForeignKey(Room, unique=False, on_delete=models.PROTECT, to_field='room_number') student_numbers = models.IntegerField('Student Numbers', default=1) course_name = models.ForeignKey(Course, unique=False, on_delete=models.PROTECT, to_field='course_name') def __str__(self): return '{}, Start {}, End {} Room {}'.format(self.course_name.course_name, self.start_date, self.end_date, self.room_number.room_number) I am registering my model using the following: class ScheduleAdmin(admin.ModelAdmin): fieldsets = [ (None, { 'fields': ['instructor', 'start_date','end_date', 'room_number', 'student_numbers', 'course_name'] }) ] def save_model(self, request, obj, form, change): # qs = super(ScheduleAdmin, self).filter(room_number=1) # qs.filter(room_number=request.POST.room_number) # if len(qs) == 0: return super(ScheduleAdmin, self).save_model(request, obj, form, change) admin.site.register(Schedule, ScheduleAdmin) This thing I am trying is apply a filter by searching the model Schedule in the database and then show the options which are of the a specific room_name. However, even if i try get_queryset and then filter or just a filter it throws an error saying the object/function is not available in the variable. How do I save a list of options based on room_name option only? I have also been trying forms to just show the available options based on room_name but couldnt get it working. Any help is welcome. -
Page matching query does not exist - Django
I have site on django. I pull it from repo, create database and do migrations by python manage.py migrate runserver without errors, but when I try open the page(localhost:8000), this is error 'Page matching query does not exist' -
How and where should I add a check condition to see if the user is above 18 years in Django?
what i want to do is, if the user is above 18 then ask him to fill up a form ... if below 18 then ask him to fill up a different form and save the form to the database views.py from django.shortcuts import render from app1.form import UserForm from django.http import HttpResponse # Create your views here. def home(request): return render(request,"home.html") def formpage(request): form=UserForm() if(request.method=='POST'): form=UserForm(request.POST) if(form.is_valid()): form.save() return home(request) return render(request,'formpage.html',{'form':form}) models.py from django.db import models # Create your models here. gen_opts= [ ('male','Male'), ('female', 'Female'), ] class MyUser(models.Model): name=models.CharField(max_length=40) gender = models.CharField(max_length=6, choices=gen_opts) age= models.PositiveIntegerField() ph.num=models.PositiveIntegerField() check_box = models.BooleanField() def __str__(self): return self.name forms.py from app1.models import MyUser from django import forms class UserForm(forms.ModelForm): class Meta(): model=MyUser fields='__all__' -
Created a brand new Django Project, attempting to run the server generates an Improperly Configured Error
I have been working on a Django Project for a bit, until I took a break. One month later I dug back in to the project and went to run the server. I received an error: django.core.exceptions.ImproperlyConfigured: Requested setting DEBUG, but settings are not configured. You must either define the environment variable DJANGO_SETTINGS_MODULE or call settings.configure() before accessing settings. I figured I must have tweaked something by accident. So I created a brand new Django Project (using a virtual environment), and just went to test the server. I received the same error. I tried the python manage.py shell solution listed in another answers but to no avail. If it helps I'm on Linux with Django version 2.1.5 and Python 3.6. -
Return the first and last (n) objects from a queryset
I'm trying to return both the first instance and last four instances of a single queryset. In this case the object instances are comments. I've tried first() and last(), negative indexing(doesn't work), Q objects etc. Can't find an answer anywhere. class Thread(models.Model): date_created = models.DateTimeField(...) ... class Comment(models.Model): thread = models.ForeignKey(Thread) ... threads = Thread.comment_set.prefetch_related('comment_set').all() I'm trying to loop through each thread in the template, and return only the first and last 4 comments (if the queryset has enough comments). I'd prefer not to turn the queryset into a list. Any ideas? thanks. -
Why does the implementation of _make_id return a tuple of two id when pass an instance method?
I read the source of Django and I am interested at the implemenation about signal. Actually, I wonder why the function _make_id returns different things which depends on arguments passed. the following code is what I am talking about def _make_id(target): if hasattr(target, '__func__'): return (id(target.__self__), id(target.__func__)) return id(target) Is there any reason not to just return the id(target)? -
Django Python App on Heroku: "Code H14 and H10"
This is my log output from Heroku when I try to run my Django app. It runs perfectly fine on my local machine. I know this is a large output, but if anybody knows how to fix it, I would hugely appreciate it. Below is a very small portion of the log. 2019-02-01T02:18:01.000000+00:00 app[api]: Build started by user delistraty1@gmail.com 2019-02-01T02:18:20.420037+00:00 heroku[web.1]: State changed from crashed to starting 2019-02-01T02:18:19.921975+00:00 app[api]: Release v14 created by user delistraty1@gmail.com 2019-02-01T02:18:19.921975+00:00 app[api]: Deploy 9f89e7b3 by user delistraty1@gmail.com 2019-02-01T02:18:26.782518+00:00 heroku[web.1]: Starting process with command : gunicorn lafusee.wsgi -b 0.0.0.0:9035 2019-02-01T02:18:29.651645+00:00 heroku[web.1]: State changed from starting to crashed 2019-02-01T02:18:35.554220+00:00 heroku[web.1]: Starting process with command : gunicorn lafusee.wsgi -b 0.0.0.0:18004 2019-02-01T02:18:37.333730+00:00 heroku[web.1]: Process exited with status 0 2019-02-01T02:18:41.257155+00:00 heroku[router]: at=error code=H10 desc="App crashed" method=GET path="/favicon.ico" host=joe-website1.herokuapp.com request_id=43056640-47d0-41cd-9c93-982d6efc8dc7 fwd="23.19.87.233" dyno= connect= service= status=503 bytes= protocol=https 2019-02-01T02:26:56.492948+00:00 heroku[web.1]: State changed from crashed to starting -
django The 'image_video' attribute has no file associated with it
Everytime i create a content with a message and without a image this error will pop-up] [https://i.stack.imgur.com/29zDq.png] But if i add a image everything perfectly work, i think i have a problem with the getting post this is the view post 1: -
why the large file upload speed is too slow in https?
Facing issue on big file upload in https. Actually the same big file uploading so fast in http for the same domain. So my request flows in the below order AWS ALB(attached ssl) -> Target groups ->ec2 instance -> nginx -> uwsgi -> django From frontend, am using jquery to upload the file and its in formdata. eg. 130mb file takes around 12min in https, around 40 seconds in http. Should I add or change any settings to fix this issue? -
List with users, with lots of data about those users. How to add the last record from a one to many table to that list for each user?
My problem: Each user has multiple contracts (some have 0). I'm trying to get the contract with the highest start date for each user and display it's start and end date in this list. Model: class Contract(models.Model): user = models.ForeignKey(User, on_delete = models.CASCADE, related_name='contracts') contract_start = models.DateField(null = True, blank = True) contract_end = models.DateField(null = True, blank = True) View: def get(self, request): users = User.objects.all().exclude(is_superuser=True) return render(request, 'user/list_all.html', { 'users': users, }) Template: {% for user in users %} <tr> <td>{{ user.employee.number }}</td> <td>{{ user.last_name }}</td> <td>{{ user.first_name }}</td> <td>{{ user.employee.location }}</td> <td>{{ Contract Start }}</td> <td>{{ Contract End }}</td> </tr> {% endfor %} I've been busy with this for a day now but can't seem to solve it. I can not use distinct() as I'm using MySQL. I've been trying to use annotate, but I either get a queryset with every user in it, while some don't have contracts, or I get the same contract date for every user. -
I can not save django user's extension
I'm not able to save the USUARIO model in the database, it saves the User and its password, plus the rest of the Model it simply ignores, I do not know what I'm doing wrong, I'm new and I'm already 5 days on top of that part of the code, I appreciate any help And it is necessary that the user be saved to be able to confirm email and the extra fields of the model USUARIO admin.py from django.contrib import admin from sistema.models import * admin.site.register(Usuario ) # Register your models here. models.py from django.db import models from django.core.files.images import ImageFile from django.core.mail import send_mail import math from multiselectfield import MultiSelectField from django.core.validators import RegexValidator from django.contrib.auth.models import User from django.db.models.signals import post_save from django.dispatch import receiver STATE_CHOICES = ( ('AC', 'Acre'), ('AL', 'Alagoas'), ('AP', 'Amapá'), ('AM', 'Amazonas'), ('BA', 'Bahia'), ('CE', 'Ceará'), ('DF', 'Distrito Federal'), ('ES', 'Espírito Santo'), ('GO', 'Goiás'), ('MA', 'Maranhão'), ('MT', 'Mato Grosso'), ('MS', 'Mato Grosso do Sul'), ('MG', 'Minas Gerais'), ('PA', 'Pará'), ('PB', 'Paraíba'), ('PR', 'Paraná'), ('PE', 'Pernambuco'), ('PI', 'Piauí'), ('RJ', 'Rio de Janeiro'), ('RN', 'Rio Grande do Norte'), ('RS', 'Rio Grande do Sul'), ('RO', 'Rondônia'), ('RR', 'Roraima'), ('SC', 'Santa Catarina'), ('SP', 'São Paulo'), ('SE', 'Sergipe'), … -
Django rest framework extremly slow (recursive relations)
For my project I started to use Laravel for the api than I switched to Django / django rest framework, I did this to gain more speed as I need to query large data. Now I got the following situation: I got a "Group" which has "Subjects" and which has a recursive relation. Now a group can have like 2000+ subjects(including the descendent subjects) a parent subject has +/- 30 subjects. This is my code: serializers class RecursiveField(serializers.Serializer): def to_representation(self, value): serializer = self.parent.parent.__class__(value, context=self.context) return serializer.data class SubjectSerializer(serializers.ModelSerializer): parent_of = RecursiveField(many=True, read_only=True) class Meta: model = Subject fields = ("id", "name", "parent_of", "parent") class GroupSerializer(serializers.ModelSerializer): subjects = SubjectSerializer(many=True, read_only=True) class Meta: model = Group fields = ("id", "name", "subjects") def setup_eager_loading(cls, queryset): return queryset.prefetch_related("subjects") views class GroupViewSet(ModelViewSet): class Paginator(BasePaginator): model = Group queryset = Group.objects.all() serializer_class = serializers.GroupSerializer pagination_class = Paginator def get_queryset(self): return self.get_serializer().setup_eager_loading(GroupViewSet.queryset) I tested the same request with the laravel api and its much faster, still noticeable slow but its ok(5-10 secs). With django rest framework its too slow (1 minute +/-), and thats just a page with 1 group that has 2500 subjects. I do know what takes long, the RecursiveField class, because when I … -
No module found name pip.cmdoptions
I am trying to run a script from command line on a red hat server but I keep getting this error saying there is no module named pip.cmdoptions. Screenshot of error message -
Checking if a user has the specific permission in a for loop looping through permissions
I'm currently looping through all permissions codename and names associated with a spesific model and putting them in a standard html table. The table is suppose to work as a permissions overview for each account (Account model), and display a check if the user has the specified permission. models.py class Account(models.Model): user = models.OneToOneField(User, on_delete=models.CASCADE) site = models.CharField(max_length=50, choices=(('all', 'all'), ('danielk', 'danielk'), ('flis', 'flis'), ('vmusic', 'vmusic')), blank=True) site_role = models.CharField(max_length=50, choices=(('Administrator', 'Administrator'), ('Moderator', 'Moderator'), ('Editor', 'Editor'))) phone_number = models.CharField(max_length=8) birth_date = models.DateField() street_adress = models.CharField(max_length=255) note = models.TextField(blank=True); zip_code = models.CharField(max_length=4) city = models.CharField(max_length=255) def formatedPhone(self, country=None): return phonenumbers.parse(Account.phone_number, "NO") """ def __str__(self): return "%s %s" % (self.User.first_name, self.user.last_name) """ def get_absolute_url(self): return reverse('account-detail', kwargs={'pk': self.pk}) class Meta: verbose_name = 'Account meta' verbose_name_plural = 'Accounts meta' permissions = ( ("has_user_hijack_permission", "Allows the user to log in as others"), ("has_user_management", "Allows a user to deactivate/delete other users"), ("has_user_site_edit", "Allows a user to edit site and role details"), ("has_user_takeout", "Can export user details"), ) views.py class cms_users_user_permissions(generic.DetailView): model = Account template_name = 'cms/users/cms-users-user-permissions.html' def get_context_data(self, **kwargs): context = super().get_context_data(**kwargs) context["permissions"] = Permission.objects.filter(content_type=ContentType.objects.get_for_model(Account)) #context['permissions'] = Permission.objects.filter(content_type_id=7) return context table.html <table class="table is-fullwidth"> <tbody> {% for permission in permissions %} <tr> <td style="width: 300px;">{{ … -
How do I make a CMS out of my django app?
I have a django app that allows admin to post articles, and users to comment on them. I also allowed admins to have their own dashboards and their own links to their articles. How do I allow admins to point their existing domains to their sites? -
Filling a choice field with objects from a query
I have a ModelForm, which I'm trying to have a dynamic select in it. My ModelForm in forms.py: class AuxiForm(forms.ModelForm): class Meta: model = Auxi fields = ["tipAux"] widgets = { 'tipAux': forms.Select(attrs={'class': 'form-control', 'placeholder': 'Tipo'}), } labels = { 'tipAux': 'Tipo', } and I want to have a choicefield which should be dynamic, filling itself by a query from an other class called TipoAux. TipoAux in models.py: class TipoAux(models.Model): denom = models.CharField(max_length=30, null=True) def __str__(self): # Python 3 return self.denom Conclusion: I'm my form I should have a dynamic select which collects its options from TipoAux class Like this: Options = ( (1, 'First option', (2, 'Second option', ) But getting its options from my DB, and not having to add them manually. -
django simple updating form logic problem
i'm trying to make a simple inventory app but i'm have trouble with restock logic for instance if i have a new stock bought with diffrent price than the first one i want just get the average price on the whole stock in shell works fine but when i go to my form i always get the form input instead of the desired value ##models class Supply(models.Model): name = models.CharField(max_length=100, unique=True) quantity = models.PositiveIntegerField() price = models.DecimalField(max_digits=11, decimal_places=2) created = models.DateField(auto_now_add=True) last_modefied = models.DateField(auto_now=True) def __str__(self): return self.name ##form class SupplyForm(forms.ModelForm): class Meta: model = Supply fields = ["name", "quantity", "price"] #view def add_supply(request): form = SupplyForm() if request.POST: # getting form input data name = request.POST.get("name") quantity = request.POST.get("quantity") price = request.POST.get("price") # getting Supply instance item = Supply.objects.get(name=name) # instantiating the form form = SupplyForm(request.POST, instance=item) if form.is_valid: # Logic old_supply = item.quantity * item.price new_supply = int(quantity) * int(price) new_quantity = item.quantity + int(quantity) item.price = (old_supply + new_supply) / new_quantity item.quantity = new_quantity form.save() return redirect("project_list") return render(request, "restock.html", {"form": form}) -
Formatting a permissions QuerySet so that it just displays the name column
I am trying to list the permissions specific to a model through a query. The goal is to just display the "name" part of the QuerySet. I'm only able to get the output below through the tag: {{ permissions }} <QuerySet [<Permission: cms | Account meta | Can add Account meta>, <Permission: cms | Account meta | Can change Account meta>, <Permission: cms | Account meta | Can delete Account meta>, <Permission: cms | Account meta | Allows the user to log in as others>, <Permission: cms | Account meta | Allows a user to deactivate/delete other users>, <Permission: cms | Account meta | Allows a user to edit site and role details>, <Permission: cms | Account meta | Can export user details>, <Permission: cms | Account meta | Can view Account meta>]> models.py class Account(models.Model): user = models.OneToOneField(User, on_delete=models.CASCADE) site = models.CharField(max_length=50, choices=(('all', 'all'), ('danielk', 'danielk'), ('flis', 'flis'), ('vmusic', 'vmusic')), blank=True) site_role = models.CharField(max_length=50, choices=(('Administrator', 'Administrator'), ('Moderator', 'Moderator'), ('Editor', 'Editor'))) phone_number = models.CharField(max_length=8) birth_date = models.DateField() street_adress = models.CharField(max_length=255) note = models.TextField(blank=True); zip_code = models.CharField(max_length=4) city = models.CharField(max_length=255) def formatedPhone(self, country=None): return phonenumbers.parse(Account.phone_number, "NO") """ def __str__(self): return "%s %s" % (self.User.first_name, self.user.last_name) """ def get_absolute_url(self): return reverse('account-detail', kwargs={'pk': … -
Bizzare problem with ModelForm and Unit Tests: TypeError: getattr(): attribute name must be string
I have no clue what could be going on here: models.py class Sound(models.Model): SEX_CHOICES = ( ('M', 'Male'), ('F', 'Female') ) phrase1 = models.CharField(max_length=300) phrase2 = models.CharField(max_length=300) language = models.CharField(max_length=50) num_words = models.PositiveSmallIntegerField(verbose_name="number of words") num_syllables = models.PositiveSmallIntegerField(verbose_name="number of syllables") sex = models.CharField(max_length=1, choices=SEX_CHOICES) voice = models.BooleanField(verbose_name="synthetic voice") speaker_name = models.CharField(max_length=50) sound_hash = models.CharField(max_length=40, primary_key=True, editable=False) key = models.CharField(max_length=200, editable=False, default="", null=True, help_text="Amazon S3 key") forms.py from django import forms class LessonSoundForm(forms.ModelForm): class Meta: model = Sound fields = ["phrase1", "phrase2", "num_words", "num_syllables"] tests.py from django.test import TestCase from forms import LessonSoundForm class LessonSoundForm(TestCase): def setUp(self): self.sound_data = { "phrase1": "Poop", "phrase2": "Knuckle", "num_words": 1, "num_syllables": 1 } def test_lesson_sound_form_validates_with_good_data(self): form = LessonSoundForm(data=self.sound_data) self.assertTrue(form.is_valid()) This seems super simple, and all other tests validate using ModelForm. I get this error, though: line 20, in test_lesson_sound_form_validates_with_good_data form = LessonSoundForm(data=self.sound_data) TypeError: __init__() got an unexpected keyword argument 'data' If I run it w/o the data argument, I get: form = LessonSoundForm(self.sound_data) File "/usr/lib/python3.6/unittest/case.py", line 397, in __init__ testMethod = getattr(self, methodName) TypeError: getattr(): attribute name must be string This seems like a very basic case, and I have no clue what could be going wrong. I assume it's just the end of the … -
django-filter doesn't work with Django REST framework
Try to use django-filters with django-rest-framework for filtering for some fields, but result doesn't change. class AiroportsViewSet(viewsets.ViewSet): queryset = Airport.objects.all() serializer_class = AiroportSerializer filter_backends = (filters.DjangoFilterBackend,) filter_fields = ('icao',) def get_permissions(self): if self.action in ['list', 'retrieve']: permission_classes = [permissions.BasePermission] else: permission_classes = [permissions.IsAuthenticated] return [permission() for permission in permission_classes] def list(self, request): serializer = self.serializer_class(self.queryset, many=True) return Response(serializer.data) def retrieve(self, request, pk=None): airport = get_object_or_404(self.queryset, pk=pk) serializer = self.serializer_class(airport) return Response(serializer.data) When i try write url:(http://localhost:8000/airportsapi/airports/?icao=ULL, result doesn't change. What i did i miss? -
Django choice field inside of the forms.py
I have a model class Book(models.Model): JANUARY = '1' FEBRUARY = '2' MARCH = '3' APRIL = '4' MAY = '5' JUNE = '6' JULY = '7' AUGUST = '8' SEPTEMBER = '9' OCTOBER = '10' NOVEMBER = '11' DECEMBER = '12' MONTH_CHOICES = ( (JANUARY, 'January'), (FEBRUARY, 'February'), (MARCH, 'March'), (APRIL, 'April'), (MAY, 'May'), (JUNE, 'June'), (JULY, 'July'), (AUGUST, 'August'), (SEPTEMBER, 'September'), (OCTOBER, 'October'), (NOVEMBER, 'November'), (DECEMBER, 'December'), ) name = models.CharField('Book name', max_length=100) author = models.ForeignKey(Author, models.SET_NULL, blank=True, null=True) author_email = models.EmailField('Author email', max_length=75, blank=True) imported = models.BooleanField(default=False) published = models.DateField('Published', blank=True, null=True) price = models.DecimalField(max_digits=10, decimal_places=2, null=True, blank=True) categories = models.ManyToManyField(Category, blank=True) month = models.CharField( max_length=2, choices= MONTH_CHOICES, default=JANUARY, ) def __str__(self): return self.name I am trying to create a field for a month inside of my queryset. How should i do that I tried Book.objects.all().values('month) but that would only give me the existing data not all the months