Hello there,
Recently i've been tasked with using the 'limit_choices_to' attribute of a ForeignKey field, in order to limit choices.
My models are like this (params -> max_length, choices, etc):
class DeviceFeatures(models.Model):
# declare choices here: feature_choices #
features = models.CharField(params)
namespace = models.CharField(params)
class Device(models.Model):
jid = models.CharField(params)
name = models.CharField(params)
features = models.ManyToManyField(DeviceFeatures)
class DeviceMember(models.Model):
device = models.ForeignKey(Device)
features = models.ForeignKey(DeviceFeatures, limit_choices_to={"feature__in": [str(feature) for feature in device.features.all()]}) (theory)
What i would like to know, is how i can access the features of a device, inside of the DeviceMember model. More exactly, i want only the features of the device that DeviceMember - ForeignKey attribute points out to.
I've been studying for some hours how limit_choices_to works...and i know this is how i'm supposed to use it, i just can't figure out how to access the features of the foreign key device.
thank you all.