I have three models
class Venue(models.Model):
property_values = models.ManyToManyField('feature.PropertyValue')
class Feature(models.Model):
name = models.CharField(max_length=255, null=False, blank=False)
class PropertyValue(models.Model):
name = models.CharField(max_length=255, null=False, blank=False)
feature = models.ForeignKey('Feature', null=False, blank=False)
In this I want to be able to configure 'feature' in venue model saying that belongs to it via property value.
Like
class Venue(models.Model):
property_values = models.ManyToManyField('feature.PropertyValue')
feature = models.ManyToManyField(via property_value something)
You already have access to feature through property_values
one = Venue.objects.first()
one.property_vaues.all()[0].feature
You can use add methods of Django objects:
https://docs.djangoproject.com/en/1.11/topics/db/examples/many_to_many/
venue = Venue.objects.get(id=1) # example
feature = Feature.objects.get(id=1) # example
venue.property_values.add(feature)
You can remove using remove function also