Created
August 14, 2022 14:24
-
-
Save Marlysson/2da4727b571980cfe003d17c03f03791 to your computer and use it in GitHub Desktop.
Custom fields django
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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})" |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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