[Cubicweb] UniqueConstraint - Data Model

Carlos Balderas carlos.balderas at gmail.com
Mon Aug 10 19:39:19 CEST 2009


Thank you, that was quick . =)

Carlos Balderas

On Mon, Aug 10, 2009 at 11:57 AM, Adrien Di Mascio <
adrien.dimascio at logilab.fr> wrote:

> 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
> necessary.
>
> Cheers,
> --
> 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
>
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://lists.cubicweb.org/pipermail/cubicweb/attachments/20090810/c1456b61/attachment-0187.html>


More information about the Cubicweb mailing list