field of tuples

2012-02-07 Thread Jaroslav Dobrek
Hello,

how can I create a field that contains tuples of entities? An example:
A model "Candidate" (someone who applies for a job) might have a field
"languages" which is a list of tuples consisting of a language and a
proficiency level.

Jaroslav

-- 
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 
django-users+unsubscr...@googlegroups.com.
For more options, visit this group at 
http://groups.google.com/group/django-users?hl=en.



Re: field of tuples

2012-02-07 Thread Sam Basl
Wouldn't it be better to do this sort of thing with a related model?
On Feb 7, 2012 4:44 AM, "Jaroslav Dobrek"  wrote:

> Hello,
>
> how can I create a field that contains tuples of entities? An example:
> A model "Candidate" (someone who applies for a job) might have a field
> "languages" which is a list of tuples consisting of a language and a
> proficiency level.
>
> Jaroslav
>
> --
> 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
> django-users+unsubscr...@googlegroups.com.
> For more options, visit this group at
> http://groups.google.com/group/django-users?hl=en.
>
>

-- 
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 
django-users+unsubscr...@googlegroups.com.
For more options, visit this group at 
http://groups.google.com/group/django-users?hl=en.



Re: field of tuples

2012-02-07 Thread akaariai
On Feb 7, 11:44 am, Jaroslav Dobrek  wrote:
> Hello,
>
> how can I create a field that contains tuples of entities? An example:
> A model "Candidate" (someone who applies for a job) might have a field
> "languages" which is a list of tuples consisting of a language and a
> proficiency level.

As others have said: don't. If you ever need to do any DB queries
involving the proficiencies of the candidates (like "how many
candidates we have who are proficient in English") you are screwed.

You will most likely get what you want with:
class CandidateLangProficiency(models.Model):
 candidate = models.ForeignKey(Candidate,
related_name='proficiencies')
 lang = models.CharField(max_length=2, choices=(('fi',
'Finnish'), ...) # Or a foreign key.
 proficiency = models.IntegerField(choices=...)
 class Meta:
 unique_together = ('candidate', 'lang')

If you can use Django 1.4, its prefetch_related will be your friend.

If you really know what you are doing you can write a custom model
field. Django's documentation should contain examples of that.

 - Anssi

-- 
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 
django-users+unsubscr...@googlegroups.com.
For more options, visit this group at 
http://groups.google.com/group/django-users?hl=en.