0

I have designed the the table with the table2.is the screen shot of my table as shown below:

Screen shot of table

This row of each column are read only i.e. screenshot.I want the row of each column should be editable.Can we have the "edittext" as column of each row in the table2 in django?

Below is my model.py

from django.db import models

    class Person(models.Model):
        date = models.CharField(verbose_name="Date",max_length=255)
        project = models.CharField(verbose_name="Project",max_length=255)
        release = models.CharField(verbose_name="Release",max_length=255)
        feature = models.CharField(verbose_name="Feature",max_length=255)
        module_name = models.CharField(verbose_name="Module Name",max_length=255)
        hours_spent = models.CharField(verbose_name="Hours spent",max_length=255)
        comment = models.CharField(verbose_name="Comment",max_length=255)

Below is the table.py.

import django_tables2 as tables
from .models import Person

class PersonTable(tables.Table):
    class Meta:
        model = Person
        # add class="paleblue" to <table> tag
        attrs = {'class': 'paleblue'}
        #fields = ('name') # fields to display

How should I edit my model.py,table.py? Please help.

Brian Tompsett - 汤莱恩
  • 5,753
  • 72
  • 57
  • 129
space earth
  • 407
  • 4
  • 18

1 Answers1

0

To make cells editable you can use html5 contenteditable attribute.

So you need to have this attribute in each td of your table. You can specify td attributes in Column definition:

class ProductsTable(tables.Table):
    date = tables.columns.Column(verbose_name="Date",max_length=255,attrs={'td': {'contenteditable': ''}})

or you can probably override __init__ method of the table to add this attribute to every column so you don't have to specify it multiple times.

This makes your table editable but it doesn't mean that you can modify your database through this table yet. You will have to do some magic with AJAX and event handling.

Check this link

Milano
  • 18,048
  • 37
  • 153
  • 353