Skip to content

Instantly share code, notes, and snippets.

@kavirajk
Last active December 6, 2015 19:15
Show Gist options
  • Save kavirajk/da51e3762bdaeaf8413e to your computer and use it in GitHub Desktop.
Save kavirajk/da51e3762bdaeaf8413e to your computer and use it in GitHub Desktop.
Models and python object difference
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]
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