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.
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.
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.
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.
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.
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.
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.
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
-~--~~~~--~~--~--~---
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
-~--~~~~--~~--~--~---
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
-~--~~~~--~~--~--~---
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
-~--~~~~--~~--~--~---
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
-~--~~~~--~~--~--~---
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
-~--~~~~--~~--~--~---
17 matches
Mail list logo
|
|