Re: Django Admin - list_display doesn't follow FK links?

2011-01-29 Thread Mathieu Möller

Hey Victor,

-
I changed my subscription to my gmail-account because I'm not sure if my 
email went trough. Here is it again.

-

I do the following to get data out of a related table/model:

Of course you could access your other model via __unicode__...
Or, simply write a function for your model and use a callback in your
list_display:

Here an easy "quick and dirty" example:

class othermodel(models.Model)
importantfield=models.CharField()

class mymodel(models.Model)
value = models.CharField()
FK_othermodel= models.Foreignkey(othermodel)

def get_importantfield(self):
return self.FK_othermodel.importantfield

In your admin.py call

MymodelAdmin(admin.ModelAdmin)
list_display=['get_importantfield']

Hope it helps!

Mathieu

--
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: Django Admin - list_display doesn't follow FK links?

2011-01-29 Thread Excite User
Hey Victor,

I do the following to get data out of a related table/model:

Of course you could access your other model via __unicode__...
Or, simply write a function for your model and use a callback in your
list_display:

Here an easy "quick and dirty" example:

class othermodel(models.Model)
importantfield=models.CharField()

class mymodel(models.Model)
value = models.CharField()
FK_othermodel= models.Foreignkey(othermodel)

def get_importantfield(self):
return self.FK_othermodel.importantfield


In your admin.py call

MymodelAdmin(admin.ModelAdmin)
list_display=['get_importantfield']

Hope it helps!

Mathieu

-- 
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: Django Admin - list_display doesn't follow FK links?

2011-01-29 Thread Daniel Roseman
On Saturday, January 29, 2011 12:28:49 PM UTC, Victor Hooi wrote:
>
> Hi,
>
> I'm trying to use list_display in the django-admin, and I can't seem to 
> find a way to get list_display to follow FK links.
>
> My models.py:
>
> class Site(models.Model):
> name = models.CharField(max_length=50, unique=True)
> description = models.TextField()
> 
> def __unicode__(self):
> return u'%s' % (self.name) 
>
> class AccommodationFeature(models.Model):
> name = models.CharField(max_length=50, unique=True)
> description = models.TextField() 
>
> class AccommodationRoom(models.Model):
> name = models.CharField(max_length=50)
> site = models.ForeignKey(Site)
> features = models.ManyToManyField(AccommodationFeature, null=True, 
> blank=True)
> 
> def __unicode__(self):
> return u'%s' % (self.name) 
>
> class BedAvailability(models.Model):
> number_of_single_beds = models.IntegerField()
> number_of_double_beds = models.IntegerField()
> conference = models.ForeignKey(Conference)
> accommodation_room = models.ForeignKey(AccommodationRoom)
> 
> class Meta:
> verbose_name_plural = 'bed availabilities'
> 
> def __unicode__(self):
> return u'Availability for %s at %s' % (self.accommodation_room, 
> self.conference)
> # Surely this isredundant? hmm, list_dispaly doesn't seem to follow 
> foreignkey relationships?
> def site_name(self):
> return u'%s' % (self.accommodation_room.site.name)
>
> Each "Site" has multiple "AccommodationRooms", which in turn have 
> "BedAvailabilities".
>
> In the BedAvailabilitiesAdmin, for list_display, I'm trying to follow 
> self.accommodation_room.site. This doesn't work using either dot notation or 
> double-underscore notation.
>
> Other ModelAdmin options seem to allow following FK links, using the double 
> underscore notation.
>
> E.g. ModelAdmin.search_fields allows you to search across FK's using:
>
> search_fields = ['foreign_key__related_fieldname']
>
>
> list_filter also seems to allow the same behaviour.
>  
> At the moment, I'm just using a function on BedAvailabilities to follow the 
> relationships and print the site name. However, this seems a bit silly when 
> logic would dictate that list_display behaves the same as search_fields and 
> list_filter.
>  
> Is there any reason this feature doesn't work for list_display?
>
> There's some discussion of it on SO:
>
>
> http://stackoverflow.com/questions/163823/can-list-display-in-a-django-modeladmin-display-attributes-of-foreignkey-fields
>
> And a ticket for it her:
>
> http://code.djangoproject.com/ticket/5863
>
> but discussion seems to have petered off. Is there a technical or design 
> reason for this?
>
> Cheers,
> Victor
>


The SO discussion you link to has several answers that give the correct 
workaround - create a method on the ModelAdmin that returns the value of the 
followed foreignkey.
--
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.



Django Admin - list_display doesn't follow FK links?

2011-01-29 Thread Victor Hooi
Hi,

I'm trying to use list_display in the django-admin, and I can't seem to find 
a way to get list_display to follow FK links.

My models.py:

class Site(models.Model):
name = models.CharField(max_length=50, unique=True)
description = models.TextField()

def __unicode__(self):
return u'%s' % (self.name) 

class AccommodationFeature(models.Model):
name = models.CharField(max_length=50, unique=True)
description = models.TextField() 

class AccommodationRoom(models.Model):
name = models.CharField(max_length=50)
site = models.ForeignKey(Site)
features = models.ManyToManyField(AccommodationFeature, null=True, 
blank=True)

def __unicode__(self):
return u'%s' % (self.name) 

class BedAvailability(models.Model):
number_of_single_beds = models.IntegerField()
number_of_double_beds = models.IntegerField()
conference = models.ForeignKey(Conference)
accommodation_room = models.ForeignKey(AccommodationRoom)

class Meta:
verbose_name_plural = 'bed availabilities'

def __unicode__(self):
return u'Availability for %s at %s' % (self.accommodation_room, 
self.conference)
# Surely this isredundant? hmm, list_dispaly doesn't seem to follow 
foreignkey relationships?
def site_name(self):
return u'%s' % (self.accommodation_room.site.name)

Each "Site" has multiple "AccommodationRooms", which in turn have 
"BedAvailabilities".

In the BedAvailabilitiesAdmin, for list_display, I'm trying to follow 
self.accommodation_room.site. This doesn't work using either dot notation or 
double-underscore notation.

Other ModelAdmin options seem to allow following FK links, using the double 
underscore notation.

E.g. ModelAdmin.search_fields allows you to search across FK's using:

search_fields = ['foreign_key__related_fieldname']


list_filter also seems to allow the same behaviour.
 
At the moment, I'm just using a function on BedAvailabilities to follow the 
relationships and print the site name. However, this seems a bit silly when 
logic would dictate that list_display behaves the same as search_fields and 
list_filter.
 
Is there any reason this feature doesn't work for list_display?

There's some discussion of it on SO:

http://stackoverflow.com/questions/163823/can-list-display-in-a-django-modeladmin-display-attributes-of-foreignkey-fields

And a ticket for it her:

http://code.djangoproject.com/ticket/5863

but discussion seems to have petered off. Is there a technical or design 
reason for this?

Cheers,
Victor

-- 
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: Missing template variable when using django admin list_display

2010-08-30 Thread Karen Tracey
On Mon, Aug 30, 2010 at 4:13 PM, christian.oudard <
christian.oud...@gmail.com> wrote:

> On Django 1.2, I'm getting a missing template variable when using a
> custom formatter in the django admin.
>
> Here is my admin class:
>
> class CustomerAdmin(admin.ModelAdmin):
>fields = [
>'name',
>]
>list_display = [
>'name',
>'customer_tenants',
>]
>def customer_tenants(self, customer):
>return u', '.join(t.subdomain for t in
> customer.tenant_set.all())
>customer_tenants.short_description = 'Tenants'
>
> The error seems to be the same one as in this ticket:
> http://code.djangoproject.com/ticket/2583
>
> Looking at the template from the admin app, the header.class_attrib
> seems to be missing. This is generated internally by django.
>
> I can fix the error by changing the template admin/
> change_list_results.html by putting an if statement around the
> {{ header.class_attrib }} variable:
>
> {% for header in result_headers %} {{ header.class_attrib }}{% endif %}>
>
> Is this an error due to improper configuration or due to a bug in
> django?
>

Do you have TEMPLATE_STRING_IF_INVALID set to something? That is documented
to be only for temporary debug purposes:
http://docs.djangoproject.com/en/dev/ref/templates/api/#invalid-template-variables.
Attempting to use the admin with TEMPLATE_STRING_IF_INVALID set to something
other than the empty string is not a good idea -- admin is one of the
specific apps noted as relying on the default value of an empty string for
invalid variable references in templates.

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



Missing template variable when using django admin list_display

2010-08-30 Thread christian.oudard
On Django 1.2, I'm getting a missing template variable when using a
custom formatter in the django admin.

Here is my admin class:

class CustomerAdmin(admin.ModelAdmin):
fields = [
'name',
]
list_display = [
'name',
'customer_tenants',
]
def customer_tenants(self, customer):
return u', '.join(t.subdomain for t in
customer.tenant_set.all())
customer_tenants.short_description = 'Tenants'

The error seems to be the same one as in this ticket:
http://code.djangoproject.com/ticket/2583

Looking at the template from the admin app, the header.class_attrib
seems to be missing. This is generated internally by django.

I can fix the error by changing the template admin/
change_list_results.html by putting an if statement around the
{{ header.class_attrib }} variable:

{% for header in result_headers %}

Is this an error due to improper configuration or due to a bug in
django?

-- 
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 at 
http://groups.google.com/group/django-users?hl=en.



Re: Admin list_display loop though sub objects and output sum of values - newbie

2010-01-18 Thread Alex Robbins
There is also an online version of one of the django books here:
http://djangobook.com/

On Jan 17, 5:08 pm, pfwd  wrote:
> Thanks fantastic thank you
> I was also able to do:
> result = obj.task_set.aggregate(Count('id'))['id__count']
> to get the a count of the tasks for quote
>
> I don't suppose you know any good books regarding Python/Django that I
> could buy to help me learn the syntax better?
>
> Many thanks
>
> On Jan 17, 10:15 pm, Daniel Roseman  wrote:
>
>
>
> > On Jan 17, 8:28 pm, pfwd  wrote:
>
> > > Hi am very new to Django/Python and I need some help with a model
> > > method
>
> > > I have two tables Linked by a foreign key and their forms are embedded
> > > in the admin interface.
> > > One table is called Quote and one table is called Task. The task table
> > > has a field called time_taken
> > > In the Quote list I want to display the total amount of time to under
> > > go all the tasks in each quote.
>
> > > This is what I'm doing and its just displaying (None) in the list
>
> > > class QuoteAdmin(admin.ModelAdmin):
> > >         fieldset = [
> > >                 (None, {'fields': ['q_number']})
> > >         ]
> > >         inlines = [TaskInline]
>
> > >         list_display = ('q_number', 'total_time','created_date')
>
> > >         def total_time(self,queryset):
> > >                 task_objs = self.Task.objects.all()
>
> > >                 total_time = 'No time taken'
>
> > >                 for record in task_objs:
> > >                         total_time = total_time + record.time_taken
> > >                 return total_time
>
> > > I'm trying to get all the tasks for each quote by doing
> > > self.Task.objects.all() and then looping through them and adding the
> > > time_taken to the var total_time.
>
> > > I guess this syntax is just plain wrong or the method is not being
> > > called as its not showing any errors
> > > I have a javascript/PHP background and I would like to learn more
> > > Python
> > > - Please be kind :)
>
> > OK a few pointers.
>
> > * a custom list_display method takes parameters (self, obj), where obj
> > is the object being displayed in that row - here it's an instance of
> > Quote.
> > * 'self.Task' means nothing. You want to get the tasks related to the
> > Quote, which is in 'obj', so you use 'obj.task_set.all()'. With this,
> > your code would work as is.
> > * A nicer way of doing it would be to get the DB to sum the time_taken
> > values. This should work:
> >     from django.db.models import Sum
> >     return obj.task_set.aggregate(Sum('time_taken'))
> > ['time_taken__sum']
> > (the square brackets at the end are needed because 'aggregate' returns
> > a dictionary, and we just want the value from there).
> > --
> > 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-us...@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: Admin list_display loop though sub objects and output sum of values - newbie

2010-01-18 Thread nostradamnit
I recommend this book - and the answer to your question is in chapter
8.
http://www.amazon.com/Practical-Django-Projects-Pratical/dp/1590599969

go ahead and get this one too
http://www.amazon.com/Python-Essential-Reference-David-Beazley/dp/0672329786/ref=pd_sim_b_4

and read http://diveintopython.org/ as well :)



On Jan 18, 12:08 am, pfwd  wrote:
> Thanks fantastic thank you
> I was also able to do:
> result = obj.task_set.aggregate(Count('id'))['id__count']
> to get the a count of the tasks for quote
>
> I don't suppose you know any good books regarding Python/Django that I
> could buy to help me learn the syntax better?
>
> Many thanks
>
> On Jan 17, 10:15 pm, Daniel Roseman  wrote:
>
> > On Jan 17, 8:28 pm, pfwd  wrote:
>
> > > Hi am very new to Django/Python and I need some help with a model
> > > method
>
> > > I have two tables Linked by a foreign key and their forms are embedded
> > > in the admin interface.
> > > One table is called Quote and one table is called Task. The task table
> > > has a field called time_taken
> > > In the Quote list I want to display the total amount of time to under
> > > go all the tasks in each quote.
>
> > > This is what I'm doing and its just displaying (None) in the list
>
> > > class QuoteAdmin(admin.ModelAdmin):
> > >         fieldset = [
> > >                 (None, {'fields': ['q_number']})
> > >         ]
> > >         inlines = [TaskInline]
>
> > >         list_display = ('q_number', 'total_time','created_date')
>
> > >         def total_time(self,queryset):
> > >                 task_objs = self.Task.objects.all()
>
> > >                 total_time = 'No time taken'
>
> > >                 for record in task_objs:
> > >                         total_time = total_time + record.time_taken
> > >                 return total_time
>
> > > I'm trying to get all the tasks for each quote by doing
> > > self.Task.objects.all() and then looping through them and adding the
> > > time_taken to the var total_time.
>
> > > I guess this syntax is just plain wrong or the method is not being
> > > called as its not showing any errors
> > > I have a javascript/PHP background and I would like to learn more
> > > Python
> > > - Please be kind :)
>
> > OK a few pointers.
>
> > * a custom list_display method takes parameters (self, obj), where obj
> > is the object being displayed in that row - here it's an instance of
> > Quote.
> > * 'self.Task' means nothing. You want to get the tasks related to the
> > Quote, which is in 'obj', so you use 'obj.task_set.all()'. With this,
> > your code would work as is.
> > * A nicer way of doing it would be to get the DB to sum the time_taken
> > values. This should work:
> >     from django.db.models import Sum
> >     return obj.task_set.aggregate(Sum('time_taken'))
> > ['time_taken__sum']
> > (the square brackets at the end are needed because 'aggregate' returns
> > a dictionary, and we just want the value from there).
> > --
> > 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-us...@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: Admin list_display loop though sub objects and output sum of values - newbie

2010-01-17 Thread pfwd
Thanks fantastic thank you
I was also able to do:
result = obj.task_set.aggregate(Count('id'))['id__count']
to get the a count of the tasks for quote

I don't suppose you know any good books regarding Python/Django that I
could buy to help me learn the syntax better?

Many thanks

On Jan 17, 10:15 pm, Daniel Roseman  wrote:
> On Jan 17, 8:28 pm, pfwd  wrote:
>
>
>
>
>
> > Hi am very new to Django/Python and I need some help with a model
> > method
>
> > I have two tables Linked by a foreign key and their forms are embedded
> > in the admin interface.
> > One table is called Quote and one table is called Task. The task table
> > has a field called time_taken
> > In the Quote list I want to display the total amount of time to under
> > go all the tasks in each quote.
>
> > This is what I'm doing and its just displaying (None) in the list
>
> > class QuoteAdmin(admin.ModelAdmin):
> >         fieldset = [
> >                 (None, {'fields': ['q_number']})
> >         ]
> >         inlines = [TaskInline]
>
> >         list_display = ('q_number', 'total_time','created_date')
>
> >         def total_time(self,queryset):
> >                 task_objs = self.Task.objects.all()
>
> >                 total_time = 'No time taken'
>
> >                 for record in task_objs:
> >                         total_time = total_time + record.time_taken
> >                 return total_time
>
> > I'm trying to get all the tasks for each quote by doing
> > self.Task.objects.all() and then looping through them and adding the
> > time_taken to the var total_time.
>
> > I guess this syntax is just plain wrong or the method is not being
> > called as its not showing any errors
> > I have a javascript/PHP background and I would like to learn more
> > Python
> > - Please be kind :)
>
> OK a few pointers.
>
> * a custom list_display method takes parameters (self, obj), where obj
> is the object being displayed in that row - here it's an instance of
> Quote.
> * 'self.Task' means nothing. You want to get the tasks related to the
> Quote, which is in 'obj', so you use 'obj.task_set.all()'. With this,
> your code would work as is.
> * A nicer way of doing it would be to get the DB to sum the time_taken
> values. This should work:
>     from django.db.models import Sum
>     return obj.task_set.aggregate(Sum('time_taken'))
> ['time_taken__sum']
> (the square brackets at the end are needed because 'aggregate' returns
> a dictionary, and we just want the value from there).
> --
> 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-us...@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: Admin list_display loop though sub objects and output sum of values - newbie

2010-01-17 Thread Daniel Roseman
On Jan 17, 8:28 pm, pfwd  wrote:
> Hi am very new to Django/Python and I need some help with a model
> method
>
> I have two tables Linked by a foreign key and their forms are embedded
> in the admin interface.
> One table is called Quote and one table is called Task. The task table
> has a field called time_taken
> In the Quote list I want to display the total amount of time to under
> go all the tasks in each quote.
>
> This is what I'm doing and its just displaying (None) in the list
>
> class QuoteAdmin(admin.ModelAdmin):
>         fieldset = [
>                 (None, {'fields': ['q_number']})
>         ]
>         inlines = [TaskInline]
>
>         list_display = ('q_number', 'total_time','created_date')
>
>         def total_time(self,queryset):
>                 task_objs = self.Task.objects.all()
>
>                 total_time = 'No time taken'
>
>                 for record in task_objs:
>                         total_time = total_time + record.time_taken
>                 return total_time
>
> I'm trying to get all the tasks for each quote by doing
> self.Task.objects.all() and then looping through them and adding the
> time_taken to the var total_time.
>
> I guess this syntax is just plain wrong or the method is not being
> called as its not showing any errors
> I have a javascript/PHP background and I would like to learn more
> Python
> - Please be kind :)

OK a few pointers.

* a custom list_display method takes parameters (self, obj), where obj
is the object being displayed in that row - here it's an instance of
Quote.
* 'self.Task' means nothing. You want to get the tasks related to the
Quote, which is in 'obj', so you use 'obj.task_set.all()'. With this,
your code would work as is.
* A nicer way of doing it would be to get the DB to sum the time_taken
values. This should work:
from django.db.models import Sum
return obj.task_set.aggregate(Sum('time_taken'))
['time_taken__sum']
(the square brackets at the end are needed because 'aggregate' returns
a dictionary, and we just want the value from there).
--
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-us...@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.




Admin list_display loop though sub objects and output sum of values - newbie

2010-01-17 Thread pfwd
Hi am very new to Django/Python and I need some help with a model
method

I have two tables Linked by a foreign key and their forms are embedded
in the admin interface.
One table is called Quote and one table is called Task. The task table
has a field called time_taken
In the Quote list I want to display the total amount of time to under
go all the tasks in each quote.

This is what I'm doing and its just displaying (None) in the list

class QuoteAdmin(admin.ModelAdmin):
fieldset = [
(None, {'fields': ['q_number']})
]
inlines = [TaskInline]

list_display = ('q_number', 'total_time','created_date')

def total_time(self,queryset):
task_objs = self.Task.objects.all()

total_time = 'No time taken'

for record in task_objs:
total_time = total_time + record.time_taken
return total_time

I'm trying to get all the tasks for each quote by doing
self.Task.objects.all() and then looping through them and adding the
time_taken to the var total_time.

I guess this syntax is just plain wrong or the method is not being
called as its not showing any errors
I have a javascript/PHP background and I would like to learn more
Python
- Please be kind :)
-- 
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 at 
http://groups.google.com/group/django-users?hl=en.




Re: admin list_display

2009-09-27 Thread paulhide

Thanks for your reply and I think you are right, I could achieve the
effect I am after (described in the middle paragraph of my first
post), but it just wouldn't be such a nice user interface as just
clicking  a link.

Paul Hide

On Sep 27, 10:05 am, Daniel Roseman <dan...@roseman.org.uk> wrote:
> On Sep 26, 12:53 pm, paulh <paul.h...@gmail.com> wrote:
>
>
>
> > Using the admin list_display and a callable with its allow_tags
> > property set to True you can plant a link for each object on the
> > changle_list display page of the admin. Is there some way of making
> > this link dynamic without having to extend the
> > ModelAdmin.changelist_view and its associated template?
>
> > The idea is to use the admin search and associated paged object
> > display for selecting an object and then using the object in a variety
> > of contexts, the context being set by the particular link that was
> > planted.
>
> > Someone seemed to be asking a question rather like this in the users
> > group not long ago and the reply seemed to be connected with reverse
> > urls, but maybe I misinterpreted this.
>
> > Paul Hide
>
> I'm not entirely sure what you're after, but it sounds like the new
> 1.1 "admin actions" functionality would be more what you need.
>
> Seehttp://docs.djangoproject.com/en/dev/ref/contrib/admin/actions/
> --
> 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: admin list_display

2009-09-27 Thread Daniel Roseman

On Sep 26, 12:53 pm, paulh <paul.h...@gmail.com> wrote:
> Using the admin list_display and a callable with its allow_tags
> property set to True you can plant a link for each object on the
> changle_list display page of the admin. Is there some way of making
> this link dynamic without having to extend the
> ModelAdmin.changelist_view and its associated template?
>
> The idea is to use the admin search and associated paged object
> display for selecting an object and then using the object in a variety
> of contexts, the context being set by the particular link that was
> planted.
>
> Someone seemed to be asking a question rather like this in the users
> group not long ago and the reply seemed to be connected with reverse
> urls, but maybe I misinterpreted this.
>
> Paul Hide

I'm not entirely sure what you're after, but it sounds like the new
1.1 "admin actions" functionality would be more what you need.

See http://docs.djangoproject.com/en/dev/ref/contrib/admin/actions/
--
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: admin list_display

2009-09-27 Thread paulhide

Having thought about this myself and done some more research, a better
question is: is there a way of getting extra args through to a
list_display callable? Having stared at the code in template_tags/
admin_list.py it would appear that there is no facility for getting
extra args through to these callables, or maybe I am looking in the
wrong place.

Paul Hide

On Sep 26, 12:53 pm, paulh <paul.h...@gmail.com> wrote:
> Using the admin list_display and a callable with its allow_tags
> property set to True you can plant a link for each object on the
> changle_list display page of the admin. Is there some way of making
> this link dynamic without having to extend the
> ModelAdmin.changelist_view and its associated template?
>
> The idea is to use the admin search and associated paged object
> display for selecting an object and then using the object in a variety
> of contexts, the context being set by the particular link that was
> planted.
>
> Someone seemed to be asking a question rather like this in the users
> group not long ago and the reply seemed to be connected with reverse
> urls, but maybe I misinterpreted this.
>
> Paul Hide
--~--~-~--~~~---~--~~
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
-~--~~~~--~~--~--~---



admin list_display

2009-09-26 Thread paulh

Using the admin list_display and a callable with its allow_tags
property set to True you can plant a link for each object on the
changle_list display page of the admin. Is there some way of making
this link dynamic without having to extend the
ModelAdmin.changelist_view and its associated template?

The idea is to use the admin search and associated paged object
display for selecting an object and then using the object in a variety
of contexts, the context being set by the particular link that was
planted.

Someone seemed to be asking a question rather like this in the users
group not long ago and the reply seemed to be connected with reverse
urls, but maybe I misinterpreted this.


Paul Hide
--~--~-~--~~~---~--~~
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: ManyToManyField in Admin list_display

2008-07-02 Thread urukay


solved



urukay wrote:
> 
> Hi,
> 
> right now I'm working on one model and it looks like this
> 
> class Area(models.Model):
>
> region = models.CharField(max_length = 2, choices =
> SLOVAK_REGION_CHOICES, radio_admin = True, db_index = True, blank = True,
> null = True)
> city = models.CharField(max_length = 4, choices =
> SLOVAK_DISTRICT_CHOICES, db_index = True)
>
> def __str__(self):
> return '%s:' '%s' %(self.region, self.city)
>    
> class Admin:
> list_display = ('region', 'city')
> 
> class JobOffer(ATag):
>
> created = models.DateTimeField(_('created'), default =
> datetime.datetime.now)
> changed = models.DateTimeField(_('changed'), default =
> datetime.datetime.now)
> name = models.CharField(_('name'), max_length=80, core = True)
> company = models.ForeignKey(Company)
> loc = models.ManyToManyField(Area)
> 
>   ...
> 
> And I wanna display field "loc" in Admin's list_display (region and also
> city field for created model), but that's impossible because it's
> ManyToManyField and only way to do that is to write down proper
> method...and that's the problem. Just can't figure it out :(
> Can anybody please help me?
> 
> Thanks a lot!!!
> 
> 

-- 
View this message in context: 
http://www.nabble.com/ManyToManyField-in-Admin-list_display-tp18245816p18246133.html
Sent from the django-users mailing list archive at Nabble.com.


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



ManyToManyField in Admin list_display

2008-07-02 Thread urukay


Hi,

right now I'm working on one model and it looks like this

class Area(models.Model):
   
region = models.CharField(max_length = 2, choices =
SLOVAK_REGION_CHOICES, radio_admin = True, db_index = True, blank = True,
null = True)
city = models.CharField(max_length = 4, choices =
SLOVAK_DISTRICT_CHOICES, db_index = True)
   
def __str__(self):
return '%s:' '%s' %(self.region, self.city)
   
class Admin:
list_display = ('region', 'city')

class JobOffer(ATag):
   
created = models.DateTimeField(_('created'), default =
datetime.datetime.now)
changed = models.DateTimeField(_('changed'), default =
datetime.datetime.now)
name = models.CharField(_('name'), max_length=80, core = True)
company = models.ForeignKey(Company)
loc = models.ManyToManyField(Area)

  ...

And I wanna display field "loc" in Admin's list_display (region and also
city field for created model), but that's impossible because it's
ManyToManyField and only way to do that is to write down proper method...and
that's the problem. Just can't figure it out :(
Can anybody please help me?

Thanks a lot!!!

-- 
View this message in context: 
http://www.nabble.com/ManyToManyField-in-Admin-list_display-tp18245816p18245816.html
Sent from the django-users mailing list archive at Nabble.com.


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