Search
 
SCRIPT & CODE EXAMPLE
 

PYTHON

custom validation in django models

from django.db import models
# importing validationerror
from django.core.exceptions import ValidationError
 
# creating a validator function
def validate_geeks_mail(value):
    if "@gmail.com" in value:
        return value
    else:
        raise ValidationError("This field accepts mail id of google only")
 
 
# Create your models here.
class GeeksModel(models.Model):
    geeks_mail = models.CharField(
                         max_length = 200,
                         validators =[validate_geeks_mail]
                         )
Comment

PREVIOUS NEXT
Code Example
Python :: find size of mongodb collection python 
Python :: sympy function definition 
Python :: pandas iterate rows 
Python :: python validate url 
Python :: how to get month name from date in pandas 
Python :: count of datatypes in columns 
Python :: select a random element from a list python 
Python :: python iterate set 
Python :: python ip address is subnet of 
Python :: max date by group pandas 
Python :: user input of int type in python 
Python :: check if two strings are anagrams python 
Python :: copy directory from one location to another python 
Python :: discord.py read embed on message 
Python :: python infinity 
Python :: how to check how many items are in a list python 
Python :: python code to print prime numbers 
Python :: python shortest distance between two points 
Python :: django id 
Python :: save_img keras 
Python :: python count code, Count number of occurrences of a given substring 
Python :: how to plot confusion matrix 
Python :: Converting Hex to RGB value in Python 
Python :: create array with unknown size in python 
Python :: type string python 
Python :: delete dataframe from memory python 
Python :: rmse python 
Python :: url settings 
Python :: string count substring occurences pytohn 
Python :: delete key value in dictionary python 
ADD CONTENT
Topic
Content
Source link
Name
5+3 =