Re: Sort by foreignkey values
On 5 jan, 01:38, Daniel Roseman wrote: > On Jan 4, 11:24 pm, Malcolm Tredinnick > wrote: > > > > > On Sun, 2009-01-04 at 20:14 -0800, Daniel Roseman wrote: > > > [...] > > > > I don't know why you say filtering Equipamento based on the value in > > > Model 'seems to be not possible'. On the contrary, it is perfectly > > > possible - that's the whole point of a relational database system. You > > > want something like: > > > Equipamento.objects.filter(modelo__manageable=True) > > > > This is documented here: > > >http://docs.djangoproject.com/en/dev/topics/db/queries/#lookups-that-... > > > The original message in this thread said "through the admin interface". > > I'm not sure if when the original questioner reposted he changed his > > use-case or omitted that key piece of information by accident, but the > > difference is significant. > > > Malcolm > > Thanks for spotting that. In which case I should have added that I > believe it is possible to use exactly the same syntax as a query > parameter in the changelist > page:http://mysite.com/admin/app/equipamento/?modelo__manageable=True > Also note that it only worked here with 0 or 1 as the values, not False or True. Don't know if it is the right, default way, or it is just database-related. --~--~-~--~~~---~--~~ 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: Sort by foreignkey values
On 5 jan, 01:38, Daniel Roseman wrote: > On Jan 4, 11:24 pm, Malcolm Tredinnick > wrote: > > > > > On Sun, 2009-01-04 at 20:14 -0800, Daniel Roseman wrote: > > > [...] > > > > I don't know why you say filtering Equipamento based on the value in > > > Model 'seems to be not possible'. On the contrary, it is perfectly > > > possible - that's the whole point of a relational database system. You > > > want something like: > > > Equipamento.objects.filter(modelo__manageable=True) > > > > This is documented here: > > >http://docs.djangoproject.com/en/dev/topics/db/queries/#lookups-that-... > > > The original message in this thread said "through the admin interface". > > I'm not sure if when the original questioner reposted he changed his > > use-case or omitted that key piece of information by accident, but the > > difference is significant. > > > Malcolm > > Thanks for spotting that. In which case I should have added that I > believe it is possible to use exactly the same syntax as a query > parameter in the changelist > page:http://mysite.com/admin/app/equipamento/?modelo__manageable=True > > Unfortunately you have to add this to the URL manually - there's no > way of getting the filter box to show this as an option, as far as I > know. One possibility would be to define a custom template for the > Equipamento changelist page which includes a hard-coded link to this > URL. > -- > DR. Hi. First of all, thank you everybody for the answers. I really meant that I wanted to do that through the admin's page filter system. I forgot to mention that on the second message I sent. I'm aware of the possibility to do this filtering through the django shell, but i couldn't implement it to work at the admin page yet. There's some interesting work being done about it (and filtering customizations in general) here: http://code.djangoproject.com/ticket/5833 But anyway, I didn't know about this neat feature of passing the shell command to the url using '?modelo__manageable=True'. I guess it's documented, but I didn't read the docs if the attention it requires. Thanks for the info. I guess that I'll try to hardcode it using the template system, while the feature is still in development. (Hope it will make it's way into trunk!) --~--~-~--~~~---~--~~ 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: Sort by foreignkey values
On Jan 4, 11:24 pm, Malcolm Tredinnick wrote: > On Sun, 2009-01-04 at 20:14 -0800, Daniel Roseman wrote: > > [...] > > > I don't know why you say filtering Equipamento based on the value in > > Model 'seems to be not possible'. On the contrary, it is perfectly > > possible - that's the whole point of a relational database system. You > > want something like: > > Equipamento.objects.filter(modelo__manageable=True) > > > This is documented here: > >http://docs.djangoproject.com/en/dev/topics/db/queries/#lookups-that-... > > The original message in this thread said "through the admin interface". > I'm not sure if when the original questioner reposted he changed his > use-case or omitted that key piece of information by accident, but the > difference is significant. > > Malcolm Thanks for spotting that. In which case I should have added that I believe it is possible to use exactly the same syntax as a query parameter in the changelist page: http://mysite.com/admin/app/equipamento/?modelo__manageable=True Unfortunately you have to add this to the URL manually - there's no way of getting the filter box to show this as an option, as far as I know. One possibility would be to define a custom template for the Equipamento changelist page which includes a hard-coded link to this URL. -- 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 django-users+unsubscr...@googlegroups.com For more options, visit this group at http://groups.google.com/group/django-users?hl=en -~--~~~~--~~--~--~---
Re: Sort by foreignkey values
On Sun, 2009-01-04 at 20:14 -0800, Daniel Roseman wrote: [...] > I don't know why you say filtering Equipamento based on the value in > Model 'seems to be not possible'. On the contrary, it is perfectly > possible - that's the whole point of a relational database system. You > want something like: > Equipamento.objects.filter(modelo__manageable=True) > > This is documented here: > http://docs.djangoproject.com/en/dev/topics/db/queries/#lookups-that-span-relationships The original message in this thread said "through the admin interface". I'm not sure if when the original questioner reposted he changed his use-case or omitted that key piece of information by accident, but the difference is significant. Malcolm --~--~-~--~~~---~--~~ 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: Sort by foreignkey values
On Jan 4, 8:30 pm, Patrick wrote: > Ok, I will rephrase that with a concrete example: > I have those to models: > > class Modelo(models.Model): > nome = models.CharField(max_length=10) > manageable = models.BooleanField() > > class Equipamento(models.Model): > modelo = models.ForeignKey(Modelo) > nome = models.CharField(max_length=20) > #manageable = models.BooleanField() > > You see, i want to be able to filter the Equipamento objects based on > the value previously attributed in Modelo, but it seems to be not > possible, since 'manageable' is not an field in Equipamento. But the > workaround would be, create that manageable field, but make it auto- > populated based on the value already defined in the Modelo object, and > hiding it from the user, at the admin page. > > How could I accomplished that? > > Any help, tips, or different approach to accomplish are welcome. > > Thank you in advance. I don't know why you say filtering Equipamento based on the value in Model 'seems to be not possible'. On the contrary, it is perfectly possible - that's the whole point of a relational database system. You want something like: Equipamento.objects.filter(modelo__manageable=True) This is documented here: http://docs.djangoproject.com/en/dev/topics/db/queries/#lookups-that-span-relationships The alternate method that you describe - adding manageable to Equipamento and populating it automatically - is called denormalization, and it's worthwhile only if you are doing a large amount of these lookups and database performance is a concern. Currently there's not built-in way to do it automatically - although there are interesting discussions going on on the developers list. You could still do it manually by defining a post-save signal for Modelo that updates all related Equipamento instances - see here for more information on signals: http://docs.djangoproject.com/en/dev/topics/signals/ -- 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 django-users+unsubscr...@googlegroups.com For more options, visit this group at http://groups.google.com/group/django-users?hl=en -~--~~~~--~~--~--~---
Re: Sort by foreignkey values
http://docs.djangoproject.com/en/dev/topics/db/queries/#topics-db-queries i would use .filter and .order_by On Jan 4, 8:30 pm, Patrick wrote: > Ok, I will rephrase that with a concrete example: > I have those to models: > > class Modelo(models.Model): > nome = models.CharField(max_length=10) > manageable = models.BooleanField() > > class Equipamento(models.Model): > modelo = models.ForeignKey(Modelo) > nome = models.CharField(max_length=20) > #manageable = models.BooleanField() > > You see, i want to be able to filter the Equipamento objects based on > the value previously attributed in Modelo, but it seems to be not > possible, since 'manageable' is not an field in Equipamento. But the > workaround would be, create that manageable field, but make it auto- > populated based on the value already defined in the Modelo object, and > hiding it from the user, at the admin page. > > How could I accomplished that? > > Any help, tips, or different approach to accomplish are welcome. > > Thank you in advance. > > On 4 jan, 18:57, Patrick wrote: > > > Hello everybody. > > > Let's say i have the models Model1 and Model2. Model1 has a > > BooleanField called Personalizabe. Model2 has a field named 'model1' > > that is a ForeignKey to Model1. > > > Is there a way, through the admin page, to filter all the Model2 > > objects according to this Personalizable attribute? > > > If not, what is the best approach to achieve this kind of stuff? --~--~-~--~~~---~--~~ 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: Sort by foreignkey values
Ok, I will rephrase that with a concrete example: I have those to models: class Modelo(models.Model): nome = models.CharField(max_length=10) manageable = models.BooleanField() class Equipamento(models.Model): modelo = models.ForeignKey(Modelo) nome = models.CharField(max_length=20) #manageable = models.BooleanField() You see, i want to be able to filter the Equipamento objects based on the value previously attributed in Modelo, but it seems to be not possible, since 'manageable' is not an field in Equipamento. But the workaround would be, create that manageable field, but make it auto- populated based on the value already defined in the Modelo object, and hiding it from the user, at the admin page. How could I accomplished that? Any help, tips, or different approach to accomplish are welcome. Thank you in advance. On 4 jan, 18:57, Patrick wrote: > Hello everybody. > > Let's say i have the models Model1 and Model2. Model1 has a > BooleanField called Personalizabe. Model2 has a field named 'model1' > that is a ForeignKey to Model1. > > Is there a way, through the admin page, to filter all the Model2 > objects according to this Personalizable attribute? > > If not, what is the best approach to achieve this kind of stuff? --~--~-~--~~~---~--~~ 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 -~--~~~~--~~--~--~---
Sort by foreignkey values
Hello everybody. Let's say i have the models Model1 and Model2. Model1 has a BooleanField called Personalizabe. Model2 has a field named 'model1' that is a ForeignKey to Model1. Is there a way, through the admin page, to filter all the Model2 objects according to this Personalizable attribute? If not, what is the best approach to achieve this kind of stuff? --~--~-~--~~~---~--~~ 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 -~--~~~~--~~--~--~---