How to get table name from Django filter objects
I have tables with same columns Like
class teachers(models.Model):
x= models..CharField(max_length=250, blank=True, null=True);
y= models..CharField(max_length=250, blank=True, null=True);
class students(models.Model):
x= models..CharField(max_length=250, blank=True, null=True);
z= models..CharField(max_length=250, blank=True, null=True);
I am using a function to process the x column of both tables. So, if any unwanted values go into the value for x, I need to write this with the column name.
Like f = students.objects.filter ()
def validate_x(obj):
if obj.x == None:
logger.error("None object found in table" + str(obj__tablename))
return False
else:
return True
for i in f:
validate_result = validate_x(i)
My actual scenario is not null validation. I just tried to explain it with this example. Is there any way to achieve this. I am using Django 1.6
+3
source to share