# Forms & APIs

**URL:** https://forum.djangoproject.com/c/users/forms-formsets/18.md

[Latest](https://forum.djangoproject.com/latest.md) · [Categories](https://forum.djangoproject.com/categories.md) · [Tags](https://forum.djangoproject.com/tags.md)

---

## [About the Forms & APIs category](https://forum.djangoproject.com/t/about-the-forms-apis-category/17682)

<div class="topic-metadata">

**Author:** [@andrewgodwin](https://forum.djangoproject.com/u/andrewgodwin)\
**Replies:** 0

</div>

Discuss Django forms, formsets, and topics related to submitting data into a Django view.

---

## [Dynamically extend serializer field list in Django REST fw](https://forum.djangoproject.com/t/dynamically-extend-serializer-field-list-in-django-rest-fw/9156)

<div class="topic-metadata">

**Author:** [@samul-1](https://forum.djangoproject.com/u/samul-1)\
**Replies:** 3\
**Last updated:** [October 9, 2026, 12:18pm UTC](https://forum.djangoproject.com/t/dynamically-extend-serializer-field-list-in-django-rest-fw/9156 "2026-10-09T12:18:14Z")

</div>

I’d like to have a model serializer in which some fields are only displayed if the request.user in the serializer context is a staff member. I know I could override the \_\_init\_\_ method and do something like: def \_\_…

---

## [How to make forms support PUT or DELETE method?](https://forum.djangoproject.com/t/how-to-make-forms-support-put-or-delete-method/45946)

<div class="topic-metadata">

**Author:** [@IgorArnaut](https://forum.djangoproject.com/u/IgorArnaut)\
**Replies:** 5\
**Last updated:** [September 9, 2026, 10:11am UTC](https://forum.djangoproject.com/t/how-to-make-forms-support-put-or-delete-method/45946 "2026-09-09T10:11:14Z")

</div>

I know that Django supports GET and POST methods in forms, but how can I make some forms use PUT or DELETE methods? For example, this form which redirects to listing-delete view. templates\\partials\\listings\\detail\\head…

---

## [max\_length messages from error\_messages do not override default message of existing MaxLengthValidators](https://forum.djangoproject.com/t/max-length-messages-from-error-messages-do-not-override-default-message-of-existing-maxlengthvalidators/45694)

<div class="topic-metadata">

**Author:** [@IgorArnaut](https://forum.djangoproject.com/u/IgorArnaut)\
**Replies:** 2\
**Last updated:** [September 1, 2026, 10:43am UTC](https://forum.djangoproject.com/t/max-length-messages-from-error-messages-do-not-override-default-message-of-existing-maxlengthvalidators/45694 "2026-09-01T10:43:44Z")

</div>

RegisterForm is based on the CustomUser model and has max\_length error messages of first\_name and last\_name set. realestate\\auth2\\forms.py: class RegisterForm(UserCreationForm): class Meta: model = CustomUs…

---

## [Case-insensitive email uniqueness with Django Simple JWT — avoiding full table scan](https://forum.djangoproject.com/t/case-insensitive-email-uniqueness-with-django-simple-jwt-avoiding-full-table-scan/45873)

<div class="topic-metadata">

**Author:** [@HushmKun](https://forum.djangoproject.com/u/HushmKun)\
**Replies:** 8\
**Last updated:** [August 31, 2026, 5:52pm UTC](https://forum.djangoproject.com/t/case-insensitive-email-uniqueness-with-django-simple-jwt-avoiding-full-table-scan/45873 "2026-08-31T17:52:55Z")

</div>

I’m using a custom User model with Django’s built-in auth system alongside djangorestframework-simplejwt on PostgreSQL. I’ve run into a case-sensitivity issue with email uniqueness. Authenticating Registering with test@…

---

## [populate data according to one field into another field in a modelForm](https://forum.djangoproject.com/t/populate-data-according-to-one-field-into-another-field-in-a-modelform/45901)

<div class="topic-metadata">

**Author:** [@sobhagiyass1991](https://forum.djangoproject.com/u/sobhagiyass1991)\
**Replies:** 1\
**Last updated:** [August 31, 2026, 1:17pm UTC](https://forum.djangoproject.com/t/populate-data-according-to-one-field-into-another-field-in-a-modelform/45901 "2026-08-31T13:17:51Z")

</div>

Hi everyone , i am a Django Novice. and i make two models such as Donor which will save Donor info with Blood group (through choices params) and Donation model which will save information of that donor . But i want to s…

---

## [Confirmation dialog if form data changed?](https://forum.djangoproject.com/t/confirmation-dialog-if-form-data-changed/45735)

<div class="topic-metadata">

**Author:** [@r-owen](https://forum.djangoproject.com/u/r-owen)\
**Replies:** 7\
**Last updated:** [August 25, 2026, 7:20am UTC](https://forum.djangoproject.com/t/confirmation-dialog-if-form-data-changed/45735 "2026-08-25T07:20:30Z")

</div>

I have a form where it is very easy to make a change that could lose data. The basics are: A main table Tune that has a bit of metadata, such as composer. A related table Score that has sheet music for the tune, and wh…

---

## [How to upload multiple images on one field in admin panel in django?](https://forum.djangoproject.com/t/how-to-upload-multiple-images-on-one-field-in-admin-panel-in-django/13493)

<div class="topic-metadata">

**Author:** [@raul-2001](https://forum.djangoproject.com/u/raul-2001)\
**Replies:** 10\
**Last updated:** [August 15, 2026, 7:20pm UTC](https://forum.djangoproject.com/t/how-to-upload-multiple-images-on-one-field-in-admin-panel-in-django/13493 "2026-08-15T19:20:59Z")

</div>

Hi dears. I would like to upload multiple images on one field in Django admin panel. Clients don’t need to upload files. Files will be uploaded only by moderators in admin panel. I tried to override the widget as it show…

---

## [ImageField validation](https://forum.djangoproject.com/t/imagefield-validation/16211)

<div class="topic-metadata">

**Author:** [@jmvermee](https://forum.djangoproject.com/u/jmvermee)\
**Replies:** 4\
**Last updated:** [August 15, 2026, 7:17pm UTC](https://forum.djangoproject.com/t/imagefield-validation/16211 "2026-08-15T19:17:51Z")

</div>

In my model I defined and ImageField() image = models.ImageField(upload\_to='images/%Y/%m/%d/', blank=True, null=True) I want to validate the uploaded image on: extensions = (‘gif’, ‘jpg’, ‘jpeg’, ‘png’) dimensions = …

---

## [Django FileField, resize image before save to S3BotoStorage](https://forum.djangoproject.com/t/django-filefield-resize-image-before-save-to-s3botostorage/7595)

<div class="topic-metadata">

**Author:** [@devspectre](https://forum.djangoproject.com/u/devspectre)\
**Replies:** 4\
**Last updated:** [July 31, 2026, 7:34am UTC](https://forum.djangoproject.com/t/django-filefield-resize-image-before-save-to-s3botostorage/7595 "2026-07-31T07:34:57Z")

</div>

Hi! I have a FileField which acutally stores an image. However, when the image is added or changed, I need to resize the image. Storage backend is s3botostorage. Here’s the mixin I wrote to resize the image which wor…

---

## [What's the best way to deliver images?](https://forum.djangoproject.com/t/whats-the-best-way-to-deliver-images/27525)

<div class="topic-metadata">

**Author:** [@sharon-yelenik](https://forum.djangoproject.com/u/sharon-yelenik)\
**Replies:** 7\
**Last updated:** [July 30, 2026, 6:52pm UTC](https://forum.djangoproject.com/t/whats-the-best-way-to-deliver-images/27525 "2026-07-30T18:52:16Z")

</div>

Here’s a simple example of how I’m delivering images. Is there a better way? # django\_app/forms.py from django.forms import ModelForm from .models import Photo class PhotoForm(ModelForm): class Meta: …

---

## [Filter Model Choice Field's custom queryset inside a Form](https://forum.djangoproject.com/t/filter-model-choice-fields-custom-queryset-inside-a-form/45581)

<div class="topic-metadata">

**Author:** [@i0Ta07](https://forum.djangoproject.com/u/i0Ta07)\
**Replies:** 2\
**Last updated:** [July 26, 2026, 8:58pm UTC](https://forum.djangoproject.com/t/filter-model-choice-fields-custom-queryset-inside-a-form/45581 "2026-07-26T20:58:06Z")

</div>

I am using a one to one field from another model and using model choice field inside the generic forms.Form but I want to filter with some parameter and that parameter is available to me in the class based view using kwa…

---

## [Django Database Cache - Untouched expired entries are never culled unless MAX\_ENTRIES is reached](https://forum.djangoproject.com/t/django-database-cache-untouched-expired-entries-are-never-culled-unless-max-entries-is-reached/22679)

<div class="topic-metadata">

**Author:** [@KonstantinSchubert](https://forum.djangoproject.com/u/KonstantinSchubert)\
**Replies:** 2\
**Last updated:** [May 29, 2026, 4:27pm UTC](https://forum.djangoproject.com/t/django-database-cache-untouched-expired-entries-are-never-culled-unless-max-entries-is-reached/22679 "2026-05-29T16:27:57Z")

</div>

The documentation for the Django database backend says: Unlike other cache backends, the database cache does not support automatic culling of expired entries at the database level. Instead, expired cache entries are c…

---

## [Sanitize invisible utf8-chars in forms / models](https://forum.djangoproject.com/t/sanitize-invisible-utf8-chars-in-forms-models/45159)

<div class="topic-metadata">

**Author:** [@profhase](https://forum.djangoproject.com/u/profhase)\
**Replies:** 1\
**Last updated:** [May 22, 2026, 2:47pm UTC](https://forum.djangoproject.com/t/sanitize-invisible-utf8-chars-in-forms-models/45159 "2026-05-22T14:47:49Z")

</div>

As of now it is possible to paste invisible unicode chars into django fields that are being stored in the database and remain in all html outputs (for copy / paste, searches, …). Shouldn’t it be a default for django to …

---

## [Django APIs for capcut video upload workflows — best practice or overkill?](https://forum.djangoproject.com/t/django-apis-for-capcut-video-upload-workflows-best-practice-or-overkill/45107)

<div class="topic-metadata">

**Author:** [@alishawinson](https://forum.djangoproject.com/u/alishawinson)\
**Replies:** 0\
**Last updated:** [May 14, 2026, 3:53pm UTC](https://forum.djangoproject.com/t/django-apis-for-capcut-video-upload-workflows-best-practice-or-overkill/45107 "2026-05-14T15:53:01Z")

</div>

Hi everyone, I’ve been exploring a workflow where capcut is used as the main editing tool, and Django acts as the backend system to manage and publish final video assets across a web platform. The idea is fairly straig…

---

## [how to get form fields for html](https://forum.djangoproject.com/t/how-to-get-form-fields-for-html/45031)

<div class="topic-metadata">

**Author:** [@monday4y](https://forum.djangoproject.com/u/monday4y)\
**Replies:** 2\
**Last updated:** [May 1, 2026, 2:37pm UTC](https://forum.djangoproject.com/t/how-to-get-form-fields-for-html/45031 "2026-05-01T14:37:10Z")

</div>

django automatically creates three fields by using usercreationform but i want to style those fields differently thats why i wanted to retrieve their field name not the label so that when i post this form , usercreationf…

---

## [Why isn't it easier to clear messages?](https://forum.djangoproject.com/t/why-isnt-it-easier-to-clear-messages/5727)

<div class="topic-metadata">

**Author:** [@ehmatthes](https://forum.djangoproject.com/u/ehmatthes)\
**Replies:** 7\
**Last updated:** [April 27, 2026, 9:42am UTC](https://forum.djangoproject.com/t/why-isnt-it-easier-to-clear-messages/5727 "2026-04-27T09:42:53Z")

</div>

I have happily just discovered the messages framework. I used to add notifications to my context dict, but I started using allauth and saw how it used messages, and I can see how it makes some notifications easier to man…

---

## [DefaultStorage object has no attribute generate\_filename](https://forum.djangoproject.com/t/defaultstorage-object-has-no-attribute-generate-filename/44954)

<div class="topic-metadata">

**Author:** [@piscvau](https://forum.djangoproject.com/u/piscvau)\
**Replies:** 0\
**Last updated:** [April 22, 2026, 5:54pm UTC](https://forum.djangoproject.com/t/defaultstorage-object-has-no-attribute-generate-filename/44954 "2026-04-22T17:54:31Z")

</div>

I have a tool to create fixtures that I use in my testserver and my django tests. This tool raises the following exception: builtins.AttributeError: ‘DefaultStorage’ object has no attribute ‘generate\_filename’ I have i…

---

## [Handle image upload with multipart form and nested data](https://forum.djangoproject.com/t/handle-image-upload-with-multipart-form-and-nested-data/44923)

<div class="topic-metadata">

**Author:** [@adeelbablu](https://forum.djangoproject.com/u/adeelbablu)\
**Replies:** 3\
**Last updated:** [April 18, 2026, 8:26am UTC](https://forum.djangoproject.com/t/handle-image-upload-with-multipart-form-and-nested-data/44923 "2026-04-18T08:26:04Z")

</div>

I have the standard Django user model and a profile model that has a oneToone with the user. So the payload for creating the whole thing at once would be: # models.py class Profile(models.Model): user = models.OneToOn…

---

## [Django export PDF directly from view](https://forum.djangoproject.com/t/django-export-pdf-directly-from-view/24349)

<div class="topic-metadata">

**Author:** [@valeriuv](https://forum.djangoproject.com/u/valeriuv)\
**Replies:** 8\
**Last updated:** [April 14, 2026, 6:47am UTC](https://forum.djangoproject.com/t/django-export-pdf-directly-from-view/24349 "2026-04-14T06:47:34Z")

</div>

I’m wondering if it’s somehow possible to process the PDF export directly in the main view, and have it triggered by a button click in the template. The reasoning is that in the main view (dispatcher\_single) I have 300 l…

---

## [django-filter and form better practices](https://forum.djangoproject.com/t/django-filter-and-form-better-practices/44649)

<div class="topic-metadata">

**Author:** [@daviddehoog](https://forum.djangoproject.com/u/daviddehoog)\
**Replies:** 0\
**Last updated:** [March 23, 2026, 1:21pm UTC](https://forum.djangoproject.com/t/django-filter-and-form-better-practices/44649 "2026-03-23T13:21:19Z")

</div>

Hi there I’ve got a Model, and a ModelForm, and I’ve been experimenting with a view that includes a form at the top driving djanggo-filter and a table with the (filtered) query set below. Initially, I set up a filters.…

---

## [Model (PDF to Image)](https://forum.djangoproject.com/t/model-pdf-to-image/8076)

<div class="topic-metadata">

**Author:** [@andresherrera9](https://forum.djangoproject.com/u/andresherrera9)\
**Replies:** 3\
**Last updated:** [March 17, 2026, 7:28am UTC](https://forum.djangoproject.com/t/model-pdf-to-image/8076 "2026-03-17T07:28:50Z")

</div>

Hello! In my app, via post form I receive a PDF file. models.py class UploadFiles(models.Model): pdf = models.FileField(upload\_to='pdf/') In my views I’ve been able to convert the PDF file to images using the pdf2…

---

## [Using background tasks in Django, but how exactly?](https://forum.djangoproject.com/t/using-background-tasks-in-django-but-how-exactly/28019)

<div class="topic-metadata">

**Author:** [@bruuhh](https://forum.djangoproject.com/u/bruuhh)\
**Replies:** 15\
**Last updated:** [March 16, 2026, 12:42am UTC](https://forum.djangoproject.com/t/using-background-tasks-in-django-but-how-exactly/28019 "2026-03-16T00:42:36Z")

</div>

Whenever a frontend client starts a session to my django backend, I need to create a specific object for some iot network. That object handles the data, the connection and provides some functionality working with said ne…

---

## [Code argument when raising validation errors](https://forum.djangoproject.com/t/code-argument-when-raising-validation-errors/8315)

<div class="topic-metadata">

**Author:** [@run\_the\_race](https://forum.djangoproject.com/u/run_the_race)\
**Replies:** 2\
**Last updated:** [March 13, 2026, 11:25am UTC](https://forum.djangoproject.com/t/code-argument-when-raising-validation-errors/8315 "2026-03-13T11:25:35Z")

</div>

In the validation docs it talks about it being good practice to pass in a code argument when raising a ValidationError. Where do these codes come from? Is there a list of them? Should I just make up my own codes as what …

---

## [How to access context from a custom django-admin command?](https://forum.djangoproject.com/t/how-to-access-context-from-a-custom-django-admin-command/18356)

<div class="topic-metadata">

**Author:** [@Alfonso00MA](https://forum.djangoproject.com/u/Alfonso00MA)\
**Replies:** 6\
**Last updated:** [March 6, 2026, 10:27pm UTC](https://forum.djangoproject.com/t/how-to-access-context-from-a-custom-django-admin-command/18356 "2026-03-06T22:27:36Z")

</div>

I have been using django.text client to examine the context of some URLs from several unit tests with a code similar to the following: from django.test import TestCase class MyTests(TestCase): def example\_test(self):…

---

## [gettext does not translate validation error messages in \_\_init\_\_](https://forum.djangoproject.com/t/gettext-does-not-translate-validation-error-messages-in-init/44352)

<div class="topic-metadata">

**Author:** [@IgorArnaut](https://forum.djangoproject.com/u/IgorArnaut)\
**Replies:** 2\
**Last updated:** [March 2, 2026, 11:39am UTC](https://forum.djangoproject.com/t/gettext-does-not-translate-validation-error-messages-in-init/44352 "2026-03-02T11:39:40Z")

</div>

Hello. I am making a real estate Django app in my language (Serbian). I made the translations in a PO file and compiled them with py manage.py compilemessages. I used simple message IDs because I’d rather not have them b…

---

## [Validating adult age does not work](https://forum.djangoproject.com/t/validating-adult-age-does-not-work/44347)

<div class="topic-metadata">

**Author:** [@IgorArnaut](https://forum.djangoproject.com/u/IgorArnaut)\
**Replies:** 4\
**Last updated:** [March 2, 2026, 9:53am UTC](https://forum.djangoproject.com/t/validating-adult-age-does-not-work/44347 "2026-03-02T09:53:55Z")

</div>

Hello. I am trying to validate the adult age, but the error message does not show. In the validator I calculate the person’s age and check if they’re adult. # realestate\\realestate\\validators.py class AdultValidator(Bas…

---

## [Using UpdateView to create a new object from an existing one](https://forum.djangoproject.com/t/using-updateview-to-create-a-new-object-from-an-existing-one/44299)

<div class="topic-metadata">

**Author:** [@piscvau](https://forum.djangoproject.com/u/piscvau)\
**Replies:** 3\
**Last updated:** [March 2, 2026, 5:01am UTC](https://forum.djangoproject.com/t/using-updateview-to-create-a-new-object-from-an-existing-one/44299 "2026-03-02T05:01:36Z")

</div>

Hello I have a very complex Model for a StitchTechnique. I would like to offer the possibility to create a new object by modifying an existing instance. I have a view which has 2 different submit buttons. one is to upd…

---

## ['NoneType' object is not callable for some reason](https://forum.djangoproject.com/t/nonetype-object-is-not-callable-for-some-reason/44255)

<div class="topic-metadata">

**Author:** [@IgorArnaut](https://forum.djangoproject.com/u/IgorArnaut)\
**Replies:** 9\
**Last updated:** [February 24, 2026, 1:18am UTC](https://forum.djangoproject.com/t/nonetype-object-is-not-callable-for-some-reason/44255 "2026-02-24T01:18:42Z")

</div>

I have this view for user registration. If the method is GET, just render the form. If the method is POST, create a form with POST data and try to validate it. Show validation errors if the fields are invalid. If the f…

---

## [default for \`choices\` field isn't default in admin form](https://forum.djangoproject.com/t/default-for-choices-field-isnt-default-in-admin-form/44189)

<div class="topic-metadata">

**Author:** [@StephanieAG](https://forum.djangoproject.com/u/StephanieAG)\
**Replies:** 3\
**Last updated:** [February 15, 2026, 12:27pm UTC](https://forum.djangoproject.com/t/default-for-choices-field-isnt-default-in-admin-form/44189 "2026-02-15T12:27:03Z")

</div>

Was playing with the choices field (see excerpt below) and trying to put the default=Difficulty.EASY, so that it defaults to EASY when creating an object but the dropdown in the django admin still defaults to VERY\_EASY I…

[Next page](https://forum.djangoproject.com/c/users/forms-formsets/18.md?page=1)
