On Sep 13, 9:25 am, Gerard Petersen <[EMAIL PROTECTED]> wrote:
> Hi All,
>
> I need to create a field with a choice set that looks like this:
>
>     BTW_CHOICES = (
>         ('0.0', '0%'),
>         ('6.0', '6%'),
>         ('19.0', '19%'),
>     )
>
> This works as expected when using dropdown lists in a form. But it needs to 
> be build from data in another model. When needed in a view I can retrieve the 
> raw data like this:
>
>     btwchoices = Meta.objects.values_list('value', 
> 'display').filter(attribute__startswith='BTW')
>
> When I put a similar line in the model class Meta is unknown. And doing a 
> 'from models import...' seems very weird when I'm IN the models module. when 
> I move it to a myfunctions.py I get import errors.
>
> from models import Meta
> ImportError: cannot import name Meta
>
> Can anybody give me some insights on how, and more importantly where, to 
> dynamically fill this BTW_CHOICES thingy.
>
> Thanx!
>
> Regards,
>
> Gerard.


If you want a field that's populated with values from another model,
you should use a ForeignKey.

Also, it's not a good idea to use Meta as the name of a model - that's
bound to get confused with the inner Meta class which defines model
meta-attributes like ordering.

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

Reply via email to