Skip to content

Instantly share code, notes, and snippets.

@Marlysson
Created August 14, 2022 14:24
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save Marlysson/2da4727b571980cfe003d17c03f03791 to your computer and use it in GitHub Desktop.
Save Marlysson/2da4727b571980cfe003d17c03f03791 to your computer and use it in GitHub Desktop.
Custom fields django
from django.db import models
class ZipField(models.Field):
def __init__(self, length=8, *args, **kwargs):
self.length = length
super().__init__(*args, **kwargs)
def db_type(self, connection):
return f"char({self.length})"
from django.db import models
from .fields import ZipField
class Address(models.Model):
zip_default = ZipField()
zip_cinco = ZipField(length=5)
zip_doze = ZipField(length=12)
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment