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='kavirajkanagaraj@gmail.com')
print(User.email)
# output: AttributeError: type object 'User' has no attribute 'email'
print(obj.email)
# output: kavirajkanagaraj@gmail.com
class EmailField(object):
def __init__(self, email=''):
self.email = email
class User(object):
email = EmailField('kavirajkanagaraj@gmail.com')
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