Viewing File: /opt/alt/python38/lib64/python3.8/site-packages/playhouse/__pycache__/gfk.cpython-38.opt-1.pyc
U
SW @ s d Z ddlT ddlmZ ddlmZ ddlmZ ddlmZ ddlmZ e Z
i ZG dd d eZG d
d deeeZdd
ZG dd de
ZG dd de
ZG dd de
ZdS )a
Provide a "Generic ForeignKey", similar to Django. A "GFK" is composed of two
columns: an object ID and an object type identifier. The object types are
collected in a global registry (all_models), so all you need to do is subclass
``gfk.Model`` and your model will be added to the registry.
Example:
class Tag(Model):
tag = CharField()
object_type = CharField(null=True)
object_id = IntegerField(null=True)
object = GFKField('object_type', 'object_id')
class Blog(Model):
tags = ReverseGFK(Tag, 'object_type', 'object_id')
class Photo(Model):
tags = ReverseGFK(Tag, 'object_type', 'object_id')
tag.object -> a blog or photo
blog.tags -> select query of tags for ``blog`` instance
Blog.tags -> select query of all tags for Blog instances
)*) BaseModel)Model)SelectQuery)UpdateQuery)with_metaclassc s e Zd Z fddZ ZS )r c s, t t| | |||} |dkr(t| | S )N)Z_metaclass_helper_r )superr __new__
all_modelsadd)clsnamebasesZattrs __class__ /gfk.pyr ' s
zBaseModel.__new__)__name__
__module____qualname__r
__classcell__r r r r r &