[BangPypers] Dynamic color for table column (color stored in model)
kracekumar ramaraju
kracethekingmaker at gmail.com
Thu Nov 17 02:33:09 CET 2011
On Wed, Nov 16, 2011 at 11:35 PM, Asif Jamadar <asif.jamadar at rezayat.net>wrote:
> I have model called TestResults
>
> models.py
> ----------
>
> Class TestResults(models)
>
> chemical_name charfield
> value floatfield
> unit charfield
> method charfield
> normal_limit charfield
> caution_limit charfield
> color charfield
>
>
> Now,
>
> The below code will generate the table for oils, which has following
> fields.
>
> views.py
> ---------
> fields = ('Test Name', 'Value', 'Unit', 'Method',
> 'Normal Limit', 'Caution Limit')
>
> all_oils = [(test.chemical_name, test.value, test.unit, test.method,
> test.normal_limit, test.caution_limit)
>
> for test in TestResult.objects.all())]
>
> oil_table = Table([fields] + all_oils
>
> oil_table.setStyle(TableStyle([('BACKGROUND', (0, 0), (-1, 0), '#a7a5a5'),
> ('FONTSIZE', (0, 0), (-1, 0), 6),
> ('GRID', (0, 0), (-1, -1), 2, '#a7a5a5'),
> ('FONTSIZE', (0, 0), (-1, -1), 8),
> ('FONTNAME',(1,1),(1,-1),'Times-Bold')]))
>
One advice is use css to set colors.In your template check for color value
="red" and then render css for that colour, else if you are using only 2
colour you can even and odd property.
*Source:*
1. *http://www.w3.org/Style/Examples/007/evenodd.en.html*
2. http://api.jquery.com/odd-selector/
In case you use jinja 2 look here http://jinja.pocoo.org/docs/tricks/.
>
> Now how can I provide dynamic color for each column. Suppose my TestResult
> model is having field for color (I,e color=red)
>
> In report i want dynamic color for second column which comes from model
> objects
>
> How can I achieve this?
> _______________________________________________
> BangPypers mailing list
> BangPypers at python.org
> http://mail.python.org/mailman/listinfo/bangpypers
>
--
*
"Talk is cheap, show me the code" - Linus Torvalds
Winning Regards
KraceKumar.R
http://kracekumar.wordpress.com
+91-97906-58304
*
*+91-85530-29521*
*
*
More information about the BangPypers
mailing list