Skip to content

Model with blank=False should map to model with required=True. #3422

@nchampsavoir

Description

@nchampsavoir

Currently a field with null=True and blank=False is mapped to a serializer field with required=False. This contradicts Django docs for blank fields:

Field.blank
If True, the field is allowed to be blank. Default is False.
Note that this is different than null. null is purely database-related, whereas blank is validation-related. >If a field has blank=True, form validation will allow entry of an empty value. If a field has blank=False, >the field will be required.

If blank is False, field should be required=True.

A model field with null=True and blank=False is useful when you want to force a user to set a foreign key (blank=False) upon object creation or modification but you want to allow the related object to be deleted with no impact on the object at hand (on_delete=SET_NULL, null=True).

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions

      pFad - Phonifier reborn

      Pfad - The Proxy pFad of © 2024 Garber Painting. All rights reserved.

      Note: This service is not intended for secure transactions such as banking, social media, email, or purchasing. Use at your own risk. We assume no liability whatsoever for broken pages.


      Alternative Proxies:

      Alternative Proxy

      pFad Proxy

      pFad v3 Proxy

      pFad v4 Proxy