How do I access the key value of a Django ForeignKey field without a table lookup? -
i have several models in django foreignkey fields linked models meaningful (non-generated) primary keys. how can set or foreignkey field of instance of such model without forcing table lookup retrieve actual object pointed to? here's example:
class country(models.model): iso = models.charfield( max_length=2, primary=true) name = models.charfield( max_length=128, null=false, blank=false) class address(models.model): street = models.charfield(max_length=64) city = models.charfield(max_length=64) country = models.foreignkey(country) i'd able set instance of address class' country field 'us' , similarly, see value ('us') without having address.country.iso , (presumably) force table lookup. how do that?
address.country_id to update:
address.country_id = 'uk' address.save() maybe need force update: address.save(force_update=true)
Comments
Post a Comment