I have a company_images
table that belongs to country_master
except when country_id is 0. If country_id is 0 i am assuming it's 'all locations'. But since 0 doesn't exist in country_master. It returns no result for those entry in company_images listing. How do i fix it.
Forgive me if this is a simple thing coz i am new to python/django.
Model.py
class CountryMaster(models.Model):
country_id = models.IntegerField(primary_key=True)
country_name = models.CharField(max_length=255)
created_date = models.DateTimeField(auto_now_add=True)
updated_date = models.DateTimeField(auto_now=True)
class Meta:
db_table = "country_master"
def __unicode__(self):
if self.country_name is None:
return "None"
else:
return self.country_name
class CompanyImage(models.Model):
image_url = models.ImageField(upload_to='company', max_length=255)
country = models.ForeignKey(CountryMaster)
created_date = models.DateTimeField(auto_now_add=True)
updated_date = models.DateTimeField(auto_now=True)
class Meta:
db_table = "company_images"
def __unicode__(self):
return "None"
I have tried this and mentioning this in admin.py as a display filed
def country_name(self):
if self.country_id is 0:
return "ALL"
else:
return self.country
country_name.short_description = 'Country'