Re: how to implement multiple choices in model

2008-11-18 Thread Karen Tracey
On Mon, Nov 17, 2008 at 9:56 PM, Canhua <[EMAIL PROTECTED]> wrote:

>
> hi, I am trying to create such a kind of field in a model. The field
> can only take one or more values from a set of value, each seperated
> by such as commas. It seems that there is no built-in field type in
> Django. How may I implement this? Any clue is greatly appreciated.
>
>
You could look into writing a custom model field:

http://docs.djangoproject.com/en/dev/howto/custom-model-fields/#howto-custom-model-fields

You might also want to look at this thread:

http://groups.google.com/group/django-users/browse_thread/thread/9bbc54473403ed86/c4efd95a675c2815
?

Karen

--~--~-~--~~~---~--~~
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
-~--~~~~--~~--~--~---



Re: how to implement multiple choices in model

2008-11-18 Thread Canhua

On Nov 18, 3:52 pm, Daniel Roseman <[EMAIL PROTECTED]>
wrote:
> Usually you'd do this as a ManyToMany field. However I know you
> sometimes do want to do it in a custom model field - I've just posted
> my implementation at 
> djangosnippets:http://www.djangosnippets.org/snippets/1200/
>

I've done that with ManyToMany field, which has some inconvenience
when display model objects as html table rows, since it is not as
convenient to display manytomany as non-related field.
--~--~-~--~~~---~--~~
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
-~--~~~~--~~--~--~---



Re: how to implement multiple choices in model

2008-11-18 Thread Canhua

On Nov 18, 3:52 pm, Daniel Roseman <[EMAIL PROTECTED]>
wrote:
> Usually you'd do this as a ManyToMany field. However I know you
> sometimes do want to do it in a custom model field - I've just posted
> my implementation at 
> djangosnippets:http://www.djangosnippets.org/snippets/1200/
>

I've done that with ManyToMany field, which has some inconvenience
when display model objects as html table rows, since it is not as
convenient to display manytomany as non-related field.
--~--~-~--~~~---~--~~
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
-~--~~~~--~~--~--~---



Re: how to implement multiple choices in model

2008-11-17 Thread Daniel Roseman

On Nov 18, 2:56 am, Canhua <[EMAIL PROTECTED]> wrote:
> hi, I am trying to create such a kind of field in a model. The field
> can only take one or more values from a set of value, each seperated
> by such as commas. It seems that there is no built-in field type in
> Django. How may I implement this? Any clue is greatly appreciated.
>
> Best wishes
>
> Can-Hua Chen

Usually you'd do this as a ManyToMany field. However I know you
sometimes do want to do it in a custom model field - I've just posted
my implementation at djangosnippets:
http://www.djangosnippets.org/snippets/1200/

--
DR.
--~--~-~--~~~---~--~~
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
-~--~~~~--~~--~--~---



how to implement multiple choices in model

2008-11-17 Thread Canhua

hi, I am trying to create such a kind of field in a model. The field
can only take one or more values from a set of value, each seperated
by such as commas. It seems that there is no built-in field type in
Django. How may I implement this? Any clue is greatly appreciated.

Best wishes

Can-Hua Chen

--~--~-~--~~~---~--~~
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
-~--~~~~--~~--~--~---



Re: multiple choices in model

2006-08-06 Thread Alan Green

On 8/5/06, Michael <[EMAIL PROTECTED]> wrote:
> Hello,
>
> From dajngo documentaytion:
>
>
>
> A choices list looks like this: YEAR_IN_SCHOOL_CHOICES = (
>  ('FR', 'Freshman'),
>  ('SO', 'Sophomore'),
>  ('JR', 'Junior'),
>  ('SR', 'Senior'),
>  ('GR', 'Graduate'),
> )
>
> Is it possible to have field with multiple choices in model like
>
> year=models.CharField(maxlength=2,
> multiplechoices=YEAR_IN_SCHOOL_CHOICES )?

Short answer: No.

Longer answer: This could be implemented with a custom model field
type, but that's a lot of work.

> The reason for that I have to write web front end for legacy application and
> they store multiple choices in DB as text field. Choices separated by new
> line.
> ManyToManyField not suitable for that case.

For just one field in just one application, I recommend treating it as
a regular text field and implementing your own rendering and
validation.

HTH,

Alan.

>
>  --
> --
> Michael
>  >
>


-- 
Alan Green
[EMAIL PROTECTED] - http://bright-green.com

--~--~-~--~~~---~--~~
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
-~--~~~~--~~--~--~---



multiple choices in model

2006-08-05 Thread Michael
Hello,From dajngo documentaytion:
A choices list looks like this:
YEAR_IN_SCHOOL_CHOICES = (('FR', 'Freshman'),('SO', 'Sophomore'),('JR', 'Junior'),('SR', 'Senior'),('GR', 'Graduate'),)Is it possible to have field with multiple choices in model like 
year=models.CharField(maxlength=2, multiplechoices=YEAR_IN_SCHOOL_CHOICES
)?The reason for that I have to write web front end for legacy application and they store multiple choices in DB as text field. Choices separated by new line.ManyToManyField not suitable for that case.
-- --Michael

--~--~-~--~~~---~--~~
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  -~--~~~~--~~--~--~---