[Answered ]-In Django, how do I add a join table relation to an existing model?

1👍

The reason this happens is because the address_tags to the CoopAddressTags which means that now the default value for the related_query_name=… parameter [Django-doc] of the ManyToManyField that targets the Address model has 'coop' as value, and this is the same name as the coop relation in the CoopAddressTags.

But the modeling is very odd. Very likely you only want to define a single ManyToManyField between Coop and Address, with the CoopAddressTags as junction table [wiki]. You thus model this as in your initial attempt.

If you need the items from the through=… model, you access this with:

my_coop.coopaddresstags_set.all()

or you can filter with:

Coop.objects.filter(coopaddresstags__is_public=True, adresses=my_address)

This will then for example retrieve all Coops for which there is a public relation between my_address and that Coop.

Leave a comment