(first of sorry bad english, hope can understand me)
well have add custom id objects of 1 of models, custom id going have letter p or l if related object have 1 or other attribute. if employee has "planta permantente" or "planta contratada" attribute custom id start p , if have "locacion de servicio" attribute start l. both need have correlative numbers. if have p1 when add new certificate employee "locacion de servicio" custom id have "l1" , next p "p2"
how can this??
this part of employee model
contract_types = ( (1, ("planta permanente")), (2, ("planta contratada")), (3, ("locación de servicio")), ) class employee(models.model): cuil = models.charfield( unique=true, max_length=11, verbose_name=_('cuil'), ) name = models.charfield( max_length=50, verbose_name=_('first name'), ) middle_name = models.charfield( blank=true, max_length=50, verbose_name=_('middle name'), ) last_name = models.charfield( max_length=100, verbose_name=_('last name'), ) have_children = models.booleanfield( default=false) contract = models.integerfield( choices=contract_types, verbose_name=_('contract'), )
and part of certificate model
class certificate(models.model): employee = models.foreignkey( employee, verbose_name=_('employee'), ) place = models.integerfield( choices=accident_place, default=1, verbose_name=_('place') ) detail = models.charfield( max_length=255, verbose_name=_('detail'), ) clinic = models.foreignkey( clinic, verbose_name=_('clinic'), )
well thats need do, if employee have contract type 1 or 2 identify p1 p2 p3...p100...pn , if 3 same l letter.
any idea?
(thanks much)
have read approach in docs: https://docs.djangoproject.com/en/1.9/ref/models/instances/#explicitly-specifying-auto-primary-key-values ?
would if manually specified custom id (a simple 'if' do?) have p1,l1 or p2 in front , save shown in django docs link above? make sure numbers consecuitive (i assume want have like: l101, p102, p103, p204 etc.?) combine custom id auto-primary key, right?
so model have auto-generated id , additionally custom id first 2 letters specified wich , following digits copy auto-generated primary-key.
hope helps!
Comments
Post a Comment