Django-tables2

999 views
Skip to first unread message

Roberto Ferreira Junior

unread,
Aug 23, 2012, 1:28:01 PM8/23/12
to django...@googlegroups.com

Hi All,

 

            I would like to ask something, I´m trying to render a table using Django-tables2 and that table has a link column that I want to link with another page, I cant figure out how can I link my model, and pass my PK to url.py.  Here’s My code:

 

############

## Models.py:  ##

############

 

class Projetos(models.Model):

 

    #FIELDS

    nome_projeto = models.CharField("Projeto", max_length=150, null='true',)

    desc_oferta = models.CharField("Descrição da oferta", max_length=500, null='true',) #aumentar

    integrador = models.CharField("Integrador", max_length=150, null='true',)

    contend_provider = models.CharField("Contend Provider", max_length=150, null='true',)

    marca_servico = models.CharField("Marca do Serviço", max_length=150, null='true',)

    valor_retry = models.IntegerField("Valor de retry", null='true',)

    la =  models.IntegerField("Large account", null='true',)

    lanc_comercial = models.DateField("Lançamento comercial", null='true')

    term_projeto = models.DateField("Término do projeto", null='true')

    data_acordo = models.DateField("Data de Acordo", null='true')

    data_revisao = models.DateField("Data de Revisão", null='true')

    ura_id =  models.IntegerField("URA ID", null='true')

    ura_desc = models.CharField("Descição URA",max_length=150, null='true')

 

############

## tables.py  ##

############

 

TEMPLATE = '''

 

   <a href="{% url project_docs  %}" >Edit</a>

 

   <a href="{% url project_edit  %}" >&nbsp upload</a>

 

'''

 

 

class ProjetosMain(tables.Table):

 

        pdb.set_trace()

        nome_projeto = tables.Column(verbose_name='Projeto',orderable=False)

        integrador = tables.Column(verbose_name='Integrador',orderable=False)

        contend_provider = tables.Column(verbose_name='CP',orderable=False)

        status = tables.Column(verbose_name='Status',orderable=False)

        term_projeto = tables.Column(verbose_name='Vigencia',orderable=False)

 

        Acoes = tables.TemplateColumn(TEMPLATE)

 

        class Meta:

            attrs = {'class': 'bordered'}

#########

##  url.py ##

#########

 

urlpatterns = patterns('',

 

    # Main Page portal

    (r'^$', portal_main_page),

 

    # Home Page

    (r'home/$', portal_main_page),

 

    # Project Page

    url(r'projetos/$', projetos_main_page),

    url(r'projetos/?P<project_id>\d{1,2,3,4}/edit/', project_edit, name="project_edit"),

    url(r'projetos/?P<project_id>\d{1,2,3,4}/docs/', project_docs, name="project_docs"),

 

    # Upload File

    (r'^uploadfile/$', uploadfile),

    (r'^uploadsuccess/$', uploadsuccess),

 

)

 

 

Best Regards / Muito Obrigado,

--

Roberto Ferreira Junior

robe...@gmail.com

11 98009942

 

Alex Strickland

unread,
Aug 24, 2012, 1:58:03 AM8/24/12
to django...@googlegroups.com
On 2012/08/24 01:49 AM, MattDale wrote:

> I love django-tables2!

May I ask why? I'm not trolling, I'd like to know more about it.

--
Regards
Alex

MattDale

unread,
Aug 24, 2012, 8:01:06 AM8/24/12
to django...@googlegroups.com
It is just a very easy way to create html tables with one simple template tag that have features like sorting by column, easy, quick css etc. without using javascript at all.  There are times when this is easier than creating a table and customizing it.  I use it for general tables that don't need any ajax features.  Although I've lately been creating manual tables and using the "tablesorter.js" to handle quick sorting.  

MattDale

unread,
Aug 24, 2012, 8:15:13 AM8/24/12
to django...@googlegroups.com
Here's an example of one of my tables.

class NeedsTable(tables.Table):
    needQuantity = tables.Column()
    prod_id = tables.Column()
    description = tables.LinkColumn('needsdetail', args=[A('pk')])
    department = tables.Column()
    order = tables.Column()
    priority = tables.Column(accessor='order.event.priority')
    show = tables.Column(accessor='order.event.name')
    preppedQuantity = tables.Column()
    prepdate = tables.Column()
    
    class Meta:
        order_by = 'priority'
        attrs = {'class': 'general_table'}

URLS.py - 
url(r'^qcarea/needs/detail/(?P<pk>\d+)/$', 'needs.views.needsdetail', name='needsdetail') 

LinkColumn uses reverse() to get its view and you use the Accessor(A) to pass the pk to the args of the reverse call.  This means that you must name your URL in your urls.py.  

In your example, I can't quite figure out what you are attempting with the TemplateColumn.  To me it seems like you need to create two link columns.  
Good Luck

Roberto Ferreira Junior

unread,
Aug 24, 2012, 8:42:07 AM8/24/12
to django...@googlegroups.com

Hi Matt,

 

            When I use linkcolum instead of a template tag, my collum cell does not display nothing!

 

Muito Obrigado,

--

Roberto Ferreira Junior

robe...@gmail.com

11 98009942

 

--
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/-/vm2VIX0jZOAJ.
To post to this group, send email to django...@googlegroups.com.
To unsubscribe from this group, send email to django-users...@googlegroups.com.
For more options, visit this group at http://groups.google.com/group/django-users?hl=en.

MattDale

unread,
Aug 24, 2012, 10:36:23 AM8/24/12
to django...@googlegroups.com
If you make that column a regular Column does it render properly? If not then confirm that you define the column exactly as it is spelled in your models.py(case and all). Once it renders properly as a regular Column, then try changing to a LinkColumn.
Reply all
Reply to author
Forward
0 new messages