Re: Foreign key with tons of items
Use "raw_id_field" useful when you have a Foreign Key on another model with lots of records. This changes the default interface from the a select box to a custom widget --~--~-~--~~~---~--~~ 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: Foreign key with tons of items
Fabio Natali wrote: > gearheart wrote: > >> maybe limit_choices_to is what you're looking for >> i had similar problem and solved with ajax autocomplete widget. >> > > I haven't yet get rid of those too-much-long inline drop down menus. > > I was thinking to use js to open up a window and let the user choose > from some hyerarchical menu... something like a first drop down menu > for the category and then a second drop down menu for the real > product, the latter being properly filtered by category. > > Could anyone provide some tips on how to get this? > > Thank you so much, > > The generic solution to this problem is to have a link in your main form that opens up the sub-window, then have the sub-window (before closing itself) set an appropriate attribute of its "opener", to set the form value in the main form. Was that what you wanted? regards Steve --~--~-~--~~~---~--~~ 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: Foreign key with tons of items
gearheart wrote: > maybe limit_choices_to is what you're looking for > i had similar problem and solved with ajax autocomplete widget. I haven't yet get rid of those too-much-long inline drop down menus. I was thinking to use js to open up a window and let the user choose from some hyerarchical menu... something like a first drop down menu for the category and then a second drop down menu for the real product, the latter being properly filtered by category. Could anyone provide some tips on how to get this? Thank you so much, -- Fabio Natali --~--~-~--~~~---~--~~ 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: Foreign key with tons of items
maybe limit_choices_to is what you're looking for i had similar problem and solved with ajax autocomplete widget. On Oct 27, 1:47 pm, paolofdr <[EMAIL PROTECTED]> wrote: > Hello everybody, > I have a similar problem: a too long drop-down menu inside an inline > element in the admin page. > Is it possible to limit the items displayed in the drop-down list, > filtering them by the value of other fields? > > Thank you > Paolo > > On 23 Ott, 18:37, Fabio Natali <[EMAIL PROTECTED]> wrote: > > > Hi everybody. > > > In my admin page I have a field for a foreign key with hundreds of > > items. That results in a drop down menu which is very difficult and > > annoying to use. > > > This is my models.py: > > > class Prod2(models.Model): > > name = models.CharField(max_length=30) > > > class Prod1(models.Model): > > name = models.CharField(max_length=30) > > belongs_to = models.ForeignKey(Prod2) > > > class Prod0(models.Model): > > name = models.CharField(max_length=30) > > belongs_to = models.ForeignKey(Prod2) > > price = models.DecimalField(max_digits=10, decimal_places=2) > > #...some more details... > > > class Purchase(models.Model): > > product = models.ForeignKey(Prod0) > > amount = models.DecimalField(max_digits=10, decimal_places=2) > > #...some more details... > > > My drop-down-menu-excessive-lenght problem arises when you want to > > create a new Purchase item via the admin page. > > > As you can see my products are organized in a hyerarchy, Prod0 being > > the real products and Prod1 and Prod2 groups and super-groups of > > products, respectively. > > > I wonder which is the best way to have a nice, friendly drop down > > menu, possibly taking advantage of the product hyerarchy (with some > > kind of multi level structure...). > > > Is there a way to customize the admin page without having to write the > > whole page from scratch? Shall I have to add some Javascript? > > > Any tips will be really appreciated. Links to code, docs and whatever > > are welcome. > > > All the best, > > > -- > > Fabio Natali > > --~--~-~--~~~---~--~~ 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: Foreign key with tons of items
Hello everybody, I have a similar problem: a too long drop-down menu inside an inline element in the admin page. Is it possible to limit the items displayed in the drop-down list, filtering them by the value of other fields? Thank you Paolo On 23 Ott, 18:37, Fabio Natali <[EMAIL PROTECTED]> wrote: > Hi everybody. > > In my admin page I have a field for a foreign key with hundreds of > items. That results in a drop down menu which is very difficult and > annoying to use. > > This is my models.py: > > class Prod2(models.Model): > name = models.CharField(max_length=30) > > class Prod1(models.Model): > name = models.CharField(max_length=30) > belongs_to = models.ForeignKey(Prod2) > > class Prod0(models.Model): > name = models.CharField(max_length=30) > belongs_to = models.ForeignKey(Prod2) > price = models.DecimalField(max_digits=10, decimal_places=2) > #...some more details... > > class Purchase(models.Model): > product = models.ForeignKey(Prod0) > amount = models.DecimalField(max_digits=10, decimal_places=2) > #...some more details... > > My drop-down-menu-excessive-lenght problem arises when you want to > create a new Purchase item via the admin page. > > As you can see my products are organized in a hyerarchy, Prod0 being > the real products and Prod1 and Prod2 groups and super-groups of > products, respectively. > > I wonder which is the best way to have a nice, friendly drop down > menu, possibly taking advantage of the product hyerarchy (with some > kind of multi level structure...). > > Is there a way to customize the admin page without having to write the > whole page from scratch? Shall I have to add some Javascript? > > Any tips will be really appreciated. Links to code, docs and whatever > are welcome. > > All the best, > > -- > Fabio Natali --~--~-~--~~~---~--~~ 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: Foreign key with tons of items
Dear Lars, thank you very much for your kind and fast reply. Lars Stavholm wrote: [...] > Have you tried filter_horizontal? > http://docs.djangoproject.com/en/dev/ref/contrib/admin/#filter-horizontal I am not sure I can really use filter_horizontal in my scenario. The actual structure I am using fom my models.py is this [0]. Hence, my "too-much-populated" drop down menu appears inside an inline element. Which, I think, makes things even worse. I really wish someone of you can help me and shed a bit of light on this. Cheers, Fabio. [0] http://dpaste.com/hold/86817/ -- Fabio Natali --~--~-~--~~~---~--~~ 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: Foreign key with tons of items
Fabio Natali wrote: > Fabio Natali wrote: > [...] >> class Prod2(models.Model): >> name = models.CharField(max_length=30) >> >> class Prod1(models.Model): >> name = models.CharField(max_length=30) >> belongs_to = models.ForeignKey(Prod2) >> >> class Prod0(models.Model): >> name = models.CharField(max_length=30) >> belongs_to = models.ForeignKey(Prod2) > > That's obviously: > belongs_to = models.ForeignKey(Prod1) > >> price = models.DecimalField(max_digits=10, decimal_places=2) >> #...some more details... >> >> class Purchase(models.Model): >> product = models.ForeignKey(Prod0) >> amount = models.DecimalField(max_digits=10, decimal_places=2) >> #...some more details... > > Sorry for the typo, bye, Fabio. > Have you tried filter_horizontal? http://docs.djangoproject.com/en/dev/ref/contrib/admin/#filter-horizontal /L --~--~-~--~~~---~--~~ 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: Foreign key with tons of items
Fabio Natali wrote: [...] > class Prod2(models.Model): > name = models.CharField(max_length=30) > > class Prod1(models.Model): > name = models.CharField(max_length=30) > belongs_to = models.ForeignKey(Prod2) > > class Prod0(models.Model): > name = models.CharField(max_length=30) > belongs_to = models.ForeignKey(Prod2) That's obviously: belongs_to = models.ForeignKey(Prod1) > price = models.DecimalField(max_digits=10, decimal_places=2) > #...some more details... > > class Purchase(models.Model): > product = models.ForeignKey(Prod0) > amount = models.DecimalField(max_digits=10, decimal_places=2) > #...some more details... Sorry for the typo, bye, Fabio. -- Fabio Natali --~--~-~--~~~---~--~~ 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 -~--~~~~--~~--~--~---
Foreign key with tons of items
Hi everybody. In my admin page I have a field for a foreign key with hundreds of items. That results in a drop down menu which is very difficult and annoying to use. This is my models.py: class Prod2(models.Model): name = models.CharField(max_length=30) class Prod1(models.Model): name = models.CharField(max_length=30) belongs_to = models.ForeignKey(Prod2) class Prod0(models.Model): name = models.CharField(max_length=30) belongs_to = models.ForeignKey(Prod2) price = models.DecimalField(max_digits=10, decimal_places=2) #...some more details... class Purchase(models.Model): product = models.ForeignKey(Prod0) amount = models.DecimalField(max_digits=10, decimal_places=2) #...some more details... My drop-down-menu-excessive-lenght problem arises when you want to create a new Purchase item via the admin page. As you can see my products are organized in a hyerarchy, Prod0 being the real products and Prod1 and Prod2 groups and super-groups of products, respectively. I wonder which is the best way to have a nice, friendly drop down menu, possibly taking advantage of the product hyerarchy (with some kind of multi level structure...). Is there a way to customize the admin page without having to write the whole page from scratch? Shall I have to add some Javascript? Any tips will be really appreciated. Links to code, docs and whatever are welcome. All the best, -- Fabio Natali --~--~-~--~~~---~--~~ 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 -~--~~~~--~~--~--~---