1👍
✅
You can do that using natural keys. You need to define natural_key()
method in Status
model and pass use_natural_foreign_keys=True
.
class Orders(models.Model):
....
status = models.ForeignKey('Status')
class Status(models.Model):
status_name = models.CharField(max_length=CHARFIELD_MAX_LEN)
#def natural_key(self):
return (self.status_name,)
Then to serialize objects
all_orders = Orders.objects.all()
resp = serializers.serialize('json', all_orders, use_natural_foreign_keys=True)
0👍
according to here:
all_orders= Orders.objects.all().values_list('status__status_name')
It will get the list of status name
- [Answer]-Unsupported operand type(s) for +: 'NoneType' and 'NoneType'
- [Answer]-Django 1.6.5 test failing before executing tests
- [Answer]-Django: View is not being accessed during edition of the table
Source:stackexchange.com