Concatenation fails when some fields are null. How to make it work concatenating the available values even if some fields are null?
The following class is from tables.py file and doesn’t display the concatenated value when some fields are not having values. How to handle this issue? We need to have the concatenation works at least for the available values . - thank you!
class ListTable(tables.Table):
addr1 = tables.Column(verbose_name="Address")
class Meta:
model = List
sequence = ("id", "Name", "addr1", "PAN", "Aadhar", "Mobile", "Email", "Remark")
fields = ("id", "Name", "addr1", "PAN", "Aadhar", "Mobile", "Email", "Remark")
template_name = "full.html"
def render_addr1(self, record, value):
return mark_safe(f"{value}, {record.addr2}, {record.addr3}, {record.City}, {record.State}, {record.Pincode}")
in the above render_addr1 function is the one which displays nothing when any of the field is of null value.
Request anyone’s help with this need. - Thank you!
There’s something else wrong not directly associated with your render_addr1
function - probably internal to that library.
Are you getting any error messages in the console when this is run?
No Ken. There isn’t any error.
When there is value in addr1 and no values with other field, the value is populated as below,
addr1 value, None, None, None, J&K, None
The other fields values won’t appear as concatenated, if there is no value to addr1 field.
addr1 field though not mandatory, for this function to work, it needs to be fed in.
Ok, that’s a different issue than what you described.
You wrote:
This is false.
The Concatenation works - it’s just that you get a value of “None”.
So change your render_addr1
method to account for that.
Right, I got to know the actual issue while investigating later on, that concatenation works but not as expected.
But could you give a hint, what change should be done?
What do you want to have happen?
Whatever it is, change your render_addr1
method to implement that.