Prevent sorting in admin

2012-08-15 Thread Timster
Picture the following model and admin:

class Section(models.Model):
position = models.PositiveIntegerField(editable=False)
title = models.CharField(max_length=200)

class SectionAdmin(admin.ModelAdmin):
list_display = ['title']
ordering = [ 'position']

The position is a column that will be automatically populated. This column 
is not editable and will not show up in the admin list display.

However, I would like to prevent the admin page from being able to sort on 
any other column. The column headers need to not be clickable and 
sort-able. 

Is there any easy way to do this?

I have dug around the docs and looked through the source a good bit, but 
couldn't find any straight-forward way of accomplishing this without 
heavily customizing the admin app.

-- 
You received this message because you are subscribed to the Google Groups 
"Django users" group.
To view this discussion on the web visit 
https://groups.google.com/d/msg/django-users/-/hcDCJEs8IfcJ.
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: sorting in /admin

2011-03-22 Thread Jason Culverhouse


> On Tue, Mar 22, 2011 at 5:29 PM, Jason Culverhouse  
> wrote:
> On Mar 22, 2011, at 12:10 PM, Bobby Roberts wrote:
> 
> > how else would you pull in information from another model into the
> > current model list view in admin?
> >
> >
> There are some options:
> Search for
> http://www.google.com/search?q=ModelAdmin+__
> 
> You'll find http://code.djangoproject.com/ticket/10743
> "Support lookup separators in ModelAdmin.list_display"
> 
> If this "bug" were fixed, your problem would be solved
> 
> There is no need for any Django change to get this to work today. All that 
> needs to be done is for the existing callables specified in list_display to 
> specify the appropriate admin_order_field value, e.g.:
> 
> 
> def Client_Lastname(self, obj):
> return  obj.CustomerId.lastName
> Client_Lastname.admin_order_field  = 'CustomerId__lastName'
> 
> Doc on admin_order_field is 
> here:http://docs.djangoproject.com/en/1.2/ref/contrib/admin/#django.contrib.admin.ModelAdmin.list_display,
>  search for admin_order_field.
> 

I missed that, I see that the latest docs
 
http://docs.djangoproject.com/en/dev/ref/contrib/admin/#django.contrib.admin.ModelAdmin.list_filter
Specifically state: "Fields in list_filter can also span relations using the __ 
lookup:"

I don't see that verbiage for other fields, perhaps a Doc enhancement is in 
order?



> Karen
> -- 
> http://tracey.org/kmt/
> 
> 
> -- 
> 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.

-- 
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: sorting in /admin

2011-03-22 Thread Karen Tracey
On Tue, Mar 22, 2011 at 5:29 PM, Jason Culverhouse wrote:

> On Mar 22, 2011, at 12:10 PM, Bobby Roberts wrote:
>
> > how else would you pull in information from another model into the
> > current model list view in admin?
> >
> >
> There are some options:
> Search for
> http://www.google.com/search?q=ModelAdmin+__
>
> You'll find http://code.djangoproject.com/ticket/10743
> "Support lookup separators in ModelAdmin.list_display"
>
> If this "bug" were fixed, your problem would be solved
>

There is no need for any Django change to get this to work today. All that
needs to be done is for the existing callables specified in list_display to
specify the appropriate admin_order_field value, e.g.:


def Client_Lastname(self, obj):
return  obj.CustomerId.lastName
Client_Lastname.admin_order_field  = 'CustomerId__lastName'

Doc on admin_order_field is here:
http://docs.djangoproject.com/en/1.2/ref/contrib/admin/#django.contrib.admin.ModelAdmin.list_display,
search for admin_order_field.

Karen
-- 
http://tracey.org/kmt/

-- 
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: sorting in /admin

2011-03-22 Thread Jason Culverhouse

On Mar 22, 2011, at 12:10 PM, Bobby Roberts wrote:

> how else would you pull in information from another model into the
> current model list view in admin?
> 
> 
There are some options:
Search for
http://www.google.com/search?q=ModelAdmin+__

You'll find http://code.djangoproject.com/ticket/10743
"Support lookup separators in ModelAdmin.list_display"

If this "bug" were fixed, your problem would be solved

Would search work as an alternative??
http://docs.djangoproject.com/en/dev/ref/contrib/admin/#django.contrib.admin.ModelAdmin.search_fields

search_fields = ['foreign_key__related_fieldname']
i.e.
search_fields = ['user__email']


You can filter on them on the right ( this isn't going to work for names) 
http://docs.djangoproject.com/en/dev/ref/contrib/admin/#django.contrib.admin.ModelAdmin.list_filter
ModelAdmin.list_filter supports __

Jason


> 
> On Mar 22, 2:41 pm, Siara  wrote:
>> Why are you doing this way ?
>> The better idea is to make it that way:
>> 
>> class YourModelAdmin(admin.ModelAdmin):
>>model = YourModel
>>list_display = [ 'firstName', 'lastName' ]
>> 
>> admin.site.register(YourModel, YourModelAdmin)
>> 
>> and i'm sure then you will be able to sort olums
>> 
>> On 22 Mar, 19:28, Bobby Roberts  wrote:
>> 
>>> I am listing the following fields from the model in /admin as follows:
>> 
>>> [...snip...]
>> 
>>> def Client_Lastname(self, obj):
>>>  return  obj.CustomerId.lastName
>> 
>>> def Client_Firstname(self, obj):
>>>  return  obj.CustomerId.firstName
>> 
>>> list_display = ('Client_Firstname', 'Client_Lastname', )
>> 
>>> [...snip...]
>> 
>>> The Firstname and Lastname fields from the Client model drop right
>>> into the list fine but I cannot sort on these fields when i click the
>>> column header.  What do I need to do to make them sortable?
> 
> -- 
> 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.
> 

-- 
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: sorting in /admin

2011-03-22 Thread Bobby Roberts
yeah we want it split into first name and last name.  That part is
working fine... i'm just trying to figure out how to get the column
sortable by clicking on the column header.

On Mar 22, 3:53 pm, Siara  wrote:
> Hmm i dont know but if you dont realy need 2 separate colums for name
> and surname you can define in Customer __unicode__ like that:
>
> def __unicode__(self):
>    return self.lastName + " " + self.firstName
>
> and then in list_diplay = ['CustomerId'],
> but that solution could give ou another problems
>
> On 22 Mar, 20:10, Bobby Roberts  wrote:
>
> > how else would you pull in information from another model into the
> > current model list view in admin?
>
> > On Mar 22, 2:41 pm, Siara  wrote:
>
> > > Why are you doing this way ?
> > > The better idea is to make it that way:
>
> > > class YourModelAdmin(admin.ModelAdmin):
> > >    model = YourModel
> > >    list_display = [ 'firstName', 'lastName' ]
>
> > > admin.site.register(YourModel, YourModelAdmin)
>
> > > and i'm sure then you will be able to sort olums
>
> > > On 22 Mar, 19:28, Bobby Roberts  wrote:
>
> > > > I am listing the following fields from the model in /admin as follows:
>
> > > > [...snip...]
>
> > > > def Client_Lastname(self, obj):
> > > >      return  obj.CustomerId.lastName
>
> > > > def Client_Firstname(self, obj):
> > > >      return  obj.CustomerId.firstName
>
> > > > list_display = ('Client_Firstname', 'Client_Lastname', )
>
> > > > [...snip...]
>
> > > > The Firstname and Lastname fields from the Client model drop right
> > > > into the list fine but I cannot sort on these fields when i click the
> > > > column header.  What do I need to do to make them sortable?

-- 
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: sorting in /admin

2011-03-22 Thread Siara
Hmm i dont know but if you dont realy need 2 separate colums for name
and surname you can define in Customer __unicode__ like that:

def __unicode__(self):
   return self.lastName + " " + self.firstName

and then in list_diplay = ['CustomerId'],
but that solution could give ou another problems

On 22 Mar, 20:10, Bobby Roberts  wrote:
> how else would you pull in information from another model into the
> current model list view in admin?
>
> On Mar 22, 2:41 pm, Siara  wrote:
>
>
>
> > Why are you doing this way ?
> > The better idea is to make it that way:
>
> > class YourModelAdmin(admin.ModelAdmin):
> >    model = YourModel
> >    list_display = [ 'firstName', 'lastName' ]
>
> > admin.site.register(YourModel, YourModelAdmin)
>
> > and i'm sure then you will be able to sort olums
>
> > On 22 Mar, 19:28, Bobby Roberts  wrote:
>
> > > I am listing the following fields from the model in /admin as follows:
>
> > > [...snip...]
>
> > > def Client_Lastname(self, obj):
> > >      return  obj.CustomerId.lastName
>
> > > def Client_Firstname(self, obj):
> > >      return  obj.CustomerId.firstName
>
> > > list_display = ('Client_Firstname', 'Client_Lastname', )
>
> > > [...snip...]
>
> > > The Firstname and Lastname fields from the Client model drop right
> > > into the list fine but I cannot sort on these fields when i click the
> > > column header.  What do I need to do to make them sortable?

-- 
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: sorting in /admin

2011-03-22 Thread Bobby Roberts
how else would you pull in information from another model into the
current model list view in admin?



On Mar 22, 2:41 pm, Siara  wrote:
> Why are you doing this way ?
> The better idea is to make it that way:
>
> class YourModelAdmin(admin.ModelAdmin):
>    model = YourModel
>    list_display = [ 'firstName', 'lastName' ]
>
> admin.site.register(YourModel, YourModelAdmin)
>
> and i'm sure then you will be able to sort olums
>
> On 22 Mar, 19:28, Bobby Roberts  wrote:
>
> > I am listing the following fields from the model in /admin as follows:
>
> > [...snip...]
>
> > def Client_Lastname(self, obj):
> >      return  obj.CustomerId.lastName
>
> > def Client_Firstname(self, obj):
> >      return  obj.CustomerId.firstName
>
> > list_display = ('Client_Firstname', 'Client_Lastname', )
>
> > [...snip...]
>
> > The Firstname and Lastname fields from the Client model drop right
> > into the list fine but I cannot sort on these fields when i click the
> > column header.  What do I need to do to make them sortable?

-- 
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: sorting in /admin

2011-03-22 Thread Siara
Why are you doing this way ?
The better idea is to make it that way:

class YourModelAdmin(admin.ModelAdmin):
   model = YourModel
   list_display = [ 'firstName', 'lastName' ]

admin.site.register(YourModel, YourModelAdmin)

and i'm sure then you will be able to sort olums

On 22 Mar, 19:28, Bobby Roberts  wrote:
> I am listing the following fields from the model in /admin as follows:
>
> [...snip...]
>
> def Client_Lastname(self, obj):
>      return  obj.CustomerId.lastName
>
> def Client_Firstname(self, obj):
>      return  obj.CustomerId.firstName
>
> list_display = ('Client_Firstname', 'Client_Lastname', )
>
> [...snip...]
>
> The Firstname and Lastname fields from the Client model drop right
> into the list fine but I cannot sort on these fields when i click the
> column header.  What do I need to do to make them sortable?

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



sorting in /admin

2011-03-22 Thread Bobby Roberts
I am listing the following fields from the model in /admin as follows:

[...snip...]

def Client_Lastname(self, obj):
 return  obj.CustomerId.lastName

def Client_Firstname(self, obj):
 return  obj.CustomerId.firstName

list_display = ('Client_Firstname', 'Client_Lastname', )

[...snip...]


The Firstname and Lastname fields from the Client model drop right
into the list fine but I cannot sort on these fields when i click the
column header.  What do I need to do to make them sortable?

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