Juanjo Conti wrote:
> Hi all,
>
> I am worried about how to model the next scene (this is an example, but 
> an appropriated one): In the model we have People, and there are 
> different kind of people, let's say: Professors, Students and Other. 
> Each People object has a 'type' attribute. Type can be P, S or O.
>
> So far, all right.
>
> Each people has an identifier that looks like: {LETTER}{NUMBER}. P1, P2, 
> P3 and S1 are examples of valid identifiers.
>
> When you instance a People object you know its type but not its number:
>
> p = People(type="S")
>
> The question is, how can I handle this numbers in my model? The count 
> should be dependent of the type.
>
> I am thinking about creating PostgreSQL sequences and use them to 
> retrieve the propitiated number each time a People is instanced:
>
> ...
> if type == "S":
>       self.number = seq_wrapper_s.next()
> elif typ == "P":
>       self.number = seq_wrapper_p.next()
> else:
>       self.number = seq_wrapper_o.next()
> ...
>
> But this will tie me to an specific data base engine. Is there a way of 
> doing this task in Django in a independent-db-engine way?
>
>   
Is there a strong reason why the count should depend on the type? Can't 
you have a more standard model with two fields - 'id' (which would be a 
normal auto-increment primary key field) and 'type' (which could be 'P', 
'S', or 'O', or else you could model it as a SmallIntegerField, with a 
set of valid choices)?

e.g.

PERSON_TYPE_CHOICES=((1,'Professor'),(2,'Student'),(3,'Other'))

class Person(models.Model)
    # (no need to put in the id field explicitly as it will be generated 
by django.)
    type=models.SmallIntegerField(choices=PERSON_TYPE_CHOICES)
    ... any other person fields.




--~--~---------~--~----~------------~-------~--~----~
You received this message because you are subscribed to the Google Groups 
"Django users" group.
To post to this group, send email to django-users@googlegroups.com
To unsubscribe from this group, send email to [EMAIL PROTECTED]
For more options, visit this group at 
http://groups.google.com/group/django-users?hl=en
-~----------~----~----~----~------~----~------~--~---

Reply via email to