Re: ordering by foreignkey again

2008-02-22 Thread bobhaugen

On Feb 22, 9:38 am, "Karen Tracey" <[EMAIL PROTECTED]> wrote:
> See the doc:
>
> http://www.djangoproject.com/documentation/model-api/#ordering
>
> where it states: "Note that, regardless of how many fields are in ordering,
> the admin site uses only the first field."

Ooops...how did I miss that?  Maybe transfixed by the earlier example
of multiple keys, maybe temporarily brain dead?

Thanks, Karen.  Will try again with a form and template outside of
admin.
--~--~-~--~~~---~--~~
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: ordering by foreignkey again

2008-02-22 Thread Karen Tracey
On Fri, Feb 22, 2008 at 9:43 AM, bobhaugen <[EMAIL PROTECTED]> wrote:

>
> Tryingg to work around the problem:
>
> Previous Avail ordering statement:
> > ordering = ('week', 'orders_product.name',
> 'orders_producer.name',)
>
> Changed my models to have sortable foreign key values:
>
> class Producer(models.Model):
>name = models.CharField(max_length=32, primary_key=True)
> [...]
> class Product(models.Model):
>name = models.CharField(max_length=32, primary_key=True)
> [...]
>
> And changed the Avail ordering statement like so:
>ordering = ('week', 'product', 'producer',)
>
> Made no difference.  Avails still display in the order in which they
> were entered.
>
> By the way, no order messages or other indication that the ordering is
> not working in either case.  Just silent failure.


There are two issues here, and I think you are only focused on the one that
isn't coming into play (ordering by foreign key). The one that is affecting
your results is ordering by multiple fields in the admin: it doesn't do it.
See the doc:

http://www.djangoproject.com/documentation/model-api/#ordering

where it states: "Note that, regardless of how many fields are in ordering,
the admin site uses only the first field."  So, since you are always
specifying 'week' (not a foreign key) as the first element in ordering, that
is the ordering you are always seeing.  I know the issue of supporting
multiple-field ordering has come up, and there was at least one ticket
opened for it (http://code.djangoproject.com/ticket/5673) but so far as I
know no work is being done to implement this (even on newforms-admin).

The ordering by foreign key oddness that currently exists is, I believe,
being dealt with on the queryset-refactor branch, but I haven't been
following the details.

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: ordering by foreignkey again

2008-02-22 Thread bobhaugen

Tryingg to work around the problem:

Previous Avail ordering statement:
> ordering = ('week', 'orders_product.name', 'orders_producer.name',)

Changed my models to have sortable foreign key values:

class Producer(models.Model):
name = models.CharField(max_length=32, primary_key=True)
[...]
class Product(models.Model):
name = models.CharField(max_length=32, primary_key=True)
[...]

And changed the Avail ordering statement like so:
ordering = ('week', 'product', 'producer',)

Made no difference.  Avails still display in the order in which they
were entered.

By the way, no order messages or other indication that the ordering is
not working in either case.  Just silent failure.
--~--~-~--~~~---~--~~
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
-~--~~~~--~~--~--~---



ordering by foreignkey again

2008-02-22 Thread bobhaugen

Django newbie wants admin list to be ordered by foreignkey names.

I understand from googling that this is a known problem, and has
apparently been fixed in the newforms admin branch.  (Do I understand
correctly?)

Questions:
1. This is a new project.  (On the other hand, I want to take it all
the way to production.) Should I just switch to the newforms admin
branch now?

2. If I want some other improvements from some other non-trunk
branches, I assume I cannot mix and match non-trunk branches.
Correct? If not, the next question may not matter.

3. Is there anything that I can easily do, without switching to a non-
trunk branch, to sort the admin list by foreignkeys now?

Here are my models:

class Producer(models.Model):
name = models.CharField(max_length=64)
def __unicode__(self):
return self.name
class Meta:
ordering = ('name',)
class Admin:
list_display = ('name',)
ordering = ('name',)

class Product(models.Model):
name = models.CharField(max_length=64)
def __unicode__(self):
return self.name
class Meta:
ordering = ('name',)
class Admin:
list_display = ('name',)
ordering = ('name',)

class Avail(models.Model):
producer = models.ForeignKey(Producer)
product = models.ForeignKey(Product)
week = models.DateField()
quantity = models.IntegerField()
class Admin:
list_display = ('week', 'product', 'producer', 'quantity')
ordering = ('week', 'orders_product.name',
'orders_producer.name',)

Avail is the list I am trying to sort by the product and producer
names.  The ordering statement is my most recent attempt to get them
sorted properly.  I've tried a few others.

Suggestions? Thanks.
--~--~-~--~~~---~--~~
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
-~--~~~~--~~--~--~---