O'Reilly logo

Python 3 Web Development Beginner's Guide by Michel Anders

Stay ahead with the world's most comprehensive technology and business learning platform.

With Safari, you learn the way you learn best. Get unlimited access to videos, live online training, learning paths, books, tutorials, and more.

Start Free Trial

No credit card required

Time for action implementing the MetaEntity and AbstractEntity classes

Let's see how this is done:

Chapter7/entity.py

class Attribute:
	def __init__(self, unique=False, notnull=False,
								default=None, affinity=None, validate=None,
								displayname=None, primary=False):
		self.coldef = (
				(affinity+' ' if not affinity is None else '') +
				('unique ' if unique else '') +
				('not null ' if notnull else '') +
				('default %s '%default if not default is None else '')
		)
		self.validate = validate
		self.displayname = displayname
		self.primary = primary

The Attribute class is mainly a vehicle to store information about attributes in a structured way. We could have used strings and parsed them, but by using an Attribute class, it is possible to explicitly recognize class variables ...

With Safari, you learn the way you learn best. Get unlimited access to videos, live online training, learning paths, books, interactive tutorials, and more.

Start Free Trial

No credit card required