Electronics & Programming

develissimo

Open Source electronics development and programming

  • You are not logged in.
  • Root
  • » Django
  • » How to options by limited_choices_to ? [RSS Feed]

#1 June 23, 2010 02:09:17

cat i.
Registered: 2009-11-02
Reputation: +  0  -
Profile   Send e-mail  

How to options by limited_choices_to ?


Hi All,

I want to built a django application for hardware compatibility
testing
Some hardwares are compatible with certain mother board. And
attributes of each hardware are different (I use a ugly table to store
attributes), which are compatible with Hardware types, such as MEM as
SIZE, HDD has Firmware ver...

class HardwareType
...........

class Hardware
type=models.ForeighKey('HardwareType')
hardware_type=models.ForeignKey('HardwareType',
limited_choice_to{'compatible_type':self.type})
attribute=ManyToManyField('hardwareAttribute')

class HardwareAttribute
compatible_type=models.ForeighKey('HardwareType')

I use limited_choice_to to limit the available options in the admin
(show compatible ones only)
But it doesn't work. The error is 'self is undefined ...'

Any one here has any idea how to to this ?

Thanking you in advance.

Homer

--
You received this message because you are subscribed to the Google Groups
"Django users" group.
To post to this group, send email to django-us...@googlegroups.com.
To unsubscribe from this group, send email to
django-users+unsubscr...@googlegroups.com.
For more options, visit this group athttp://groups.google.com/group/django-users?hl=en.

Offline

#2 June 23, 2010 09:17:17

e.
Registered: 2009-11-02
Reputation: +  0  -
Profile   Send e-mail  

How to options by limited_choices_to ?


First of all you might want to reconsider not using the name "type"
for one of your fields as it is a builtin in python.

I guess what you could do it limit the choices using the choices
keyword in the field constructor. However, since this appears to be
dynamic you would need to set it in the model's constructor, e.g.

class Hardware(models.Model):
...
def __init__(self, *args, **kwargs):
self.fields.choices =
HardwareType.objects.all().values_list('pk', 'name'))

I'm guessing at what the fields on HardwareType might be here.

Euan

On Jun 23, 2:06 am, cat in a tub <luj...@gmail.com> wrote:
> Hi All,
>
> I want to built a django application for hardware compatibility
> testing
> Some hardwares are compatible with certain mother board. And
> attributes of each hardware are different (I use a ugly table to store
> attributes), which are compatible with Hardware types, such as MEM as
> SIZE, HDD has Firmware ver...
>
> class HardwareType
> ...........
>
> class Hardware
> type=models.ForeighKey('HardwareType')
> hardware_type=models.ForeignKey('HardwareType',
> limited_choice_to{'compatible_type':self.type})
> attribute=ManyToManyField('hardwareAttribute')
>
> class HardwareAttribute
> compatible_type=models.ForeighKey('HardwareType')
>
> I use limited_choice_to to limit the available options in the admin
> (show compatible ones only)
> But it doesn't work. The error is 'self is undefined ...'
>
> Any one here has any idea how to to this ?
>
> Thanking you in advance.
>
> Homer

--
You received this message because you are subscribed to the Google Groups
"Django users" group.
To post to this group, send email to django-us...@googlegroups.com.
To unsubscribe from this group, send email to
django-users+unsubscr...@googlegroups.com.
For more options, visit this group athttp://groups.google.com/group/django-users?hl=en.

Offline

  • Root
  • » Django
  • » How to options by limited_choices_to ? [RSS Feed]

Board footer

Moderator control

Enjoy the 20th of October
PoweredBy

The Forums are managed by develissimo stuff members, if you find any issues or misplaced content please help us to fix it. Thank you! Tell us via Contact Options
Leave a Message
Welcome to Develissimo Live Support