Opened 3 years ago

Closed 3 years ago

Last modified 3 years ago

#33016 closed Uncategorized (invalid)

Cannot override choices error_messages in model

Reported by: Suneeth S Owned by: nobody
Component: Database layer (models, ORM) Version: 3.2
Severity: Normal Keywords:
Cc: Triage Stage: Unreviewed
Has patch: no Needs documentation: no
Needs tests: no Patch needs improvement: no
Easy pickings: no UI/UX: no

Description

I have a model class (from django.db.model) and a char field with choices attribute, my form is not created from django form and i am using a serializer in the middle of the model and my static HTML form when validating my choices field (dropdown) it shows the default validation messages only, i couldn't override the error messages. Thanks in advance.

here is my code

class CustomUser(BaseModel, AbstractUser):

type = models.CharField(choices=TYPES, max_length=20, default='super_admin',error_messages={"null":'Value is not a valid.',"blank":'Value is not a valid.',"invalid_choice":'Value is not a valid.'})

note: Base model inherited from models.Model

Change History (3)

comment:1 by Suneeth S, 3 years ago

Sorry, I have fixed the issue in serializer like this,
extra_kwargs = {"type": {"error_messages": {"null": "Value cannot be null"}}}

comment:2 by Suneeth S, 3 years ago

Resolution: fixed
Status: newclosed

comment:3 by Jacob Walls, 3 years ago

Resolution: fixedinvalid
Note: See TracTickets for help on using tickets.
Back to Top