Last active
December 6, 2015 19:15
-
-
Save kavirajk/da51e3762bdaeaf8413e to your computer and use it in GitHub Desktop.
Models and python object difference
This file contains 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 User(models.Model): | |
email = models.EmailField() | |
obj = User(email='[email protected]') | |
print(User.email) | |
# output: AttributeError: type object 'User' has no attribute 'email' | |
print(obj.email) | |
# output: [email protected] |
This file contains 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
class EmailField(object): | |
def __init__(self, email=''): | |
self.email = email | |
class User(object): | |
email = EmailField('[email protected]') | |
obj = User() | |
print(User.email) | |
# output: <__main__.EmailField object at 0x7f59e81e8550> | |
print(obj.email) | |
# output: <__main__.EmailField object at 0x7f59e81e8550> |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment