[Answer]-How do I represent a cassandra user defined type in a python model in cqlengine

0👍

Apparently, this feature is not yet supported in cqlengine and there is development towards providing this in the near future. So for the time being, its back to utlizing the cassandra python driver provided by datastax to have this working in the code. I’ll be looking out for when the cqlengine implementation is available and feed back here.

👤Jome

1👍

The UDT support is available with cqlengine, please refer this

from cassandra.cqlengine.columns import *
from cassandra.cqlengine.models import Model
from cassandra.cqlengine.usertype import UserType

class address(UserType):
    street = Text()
    zipcode = Integer()

class users(Model):
    __keyspace__ = 'account'
    name = Text(primary_key=True)
    addr = UserDefinedType(address)

sync_table(users)

users.create(name="Joe", addr=address(street="Easy St.", zip=99999))
user = users.objects(name="Joe")[0]
print user.name, user.addr
# Joe {'street': Easy St., 'zipcode': None}

Leave a comment