kolistivra
kolistivra

Reputation: 4429

Is it possible to have an entity kind with no property?

I would like to keep a list of 'things' in Datastore. No other information other than their names are required for these 'things', and these names must be unique, i.e. they can be thought as key_name for an entity. In this case, I don't need any explicit property/field for the entity kind (since the name of a 'thing' can be kept inside key_name of an entity). Is this possible? How? The alternative is to replicate this piece of information by having a dedicated field/property for name.

class EntityKindWithNoProperty(db.Model):
    name = db.StringProperty()

I feel like this approach is duplication of information. What do you think?

Upvotes: 2

Views: 80

Answers (2)

Paul Collingwood
Paul Collingwood

Reputation: 9116

This works

class Empty(ndb.Model):
    pass

e = Empty(id="somestring")
e.put()

For uniqueness you can potentially generate the IDs in advance then consume them one by one with numeric keys. Or, depending on your use model, get_or_insert.

Upvotes: 3

dlorenc
dlorenc

Reputation: 531

Have you considered having a single entity with a list property?

class ThingSingleton(db.Model):
    things = db.StringListProperty()

The best approach to use would depend on your query patterns and the expected cardinality of things.

Upvotes: 0

Related Questions