[Cubicweb] UniqueConstraint - Data Model

Adrien Di Mascio adrien.dimascio at logilab.fr
Mon Aug 10 18:57:13 CEST 2009

Hi Carlos,

On Monday 10 August 2009 18:48:50 Carlos Balderas wrote:
> class Person(EntityType):
>         name = String()
>         folder = Int (constraint = [UniqueConstraint()])
> Without the constraint I can use this url to find person entity:
> http://localhost/person/301  <-- {eid}, but if I use the unique constraint
> then I have to use this url http://localhost/person/1 <--- {folder}

This is the default behaviour in CubicWeb. You can bypass it by defining 
the ``rest_attr`` class attribute on your entity class :

class Person(AnyEntity):
    id = 'Person'
    rest_attr = 'eid'

This should be enough for CubicWeb to use 'eid' as the default attribute in 
your urls. You can also go deeper to have more control on the generated urls
(take a look at cubicweb/entity.py and the rest_* methods) but this is rarely

Adrien Di Mascio                              LOGILAB, Paris (France).
Formations Python,Zope,Debian,Calcul    http://www.logilab.fr/formations
Développement logiciel sur mesure:      http://www.logilab.fr/services
Informatique scientifique:              http://www.logilab.fr/science
Gestion de connaissances:               http://www.cubicweb.org/
Python in Python:     http://codespeak.net/pypy/dist/pypy/doc/index.html

More information about the Cubicweb mailing list