jazzband / django-taggit

Simple tagging for django
https://django-taggit.readthedocs.io
BSD 3-Clause "New" or "Revised" License
3.33k stars 622 forks source link

Add support for initialising tags via a list on object creation #864

Open waveywhite opened 1 year ago

waveywhite commented 1 year ago

It should be possible to initialise tags via a list

class` MyModel(models.Model):
    tags=TaggableManager()

ob = MyModel(tags=['tag1', 'tag2'])
ob.save()

assert( len( MyModel.objects.filter[tags__name__in=['tag1'] ) ) == 1 )
rtpg commented 1 year ago

I totally understand wanting this, but basically taggit is following how M2M models work in Django in general. This involves needing to save the "owning" model first (to have an id to be associated to), and generally all the APIs treat this stuff as "you save it immediately", because doing otherwise leads to weird confusing code. Hence stuff like .set.

I haven't seen any other library venture into this territory, so am afraid to do so myself. If anyone has seen another library in the wild handle many-to-many relationships in this way, please share links here! It could provide good information on how to deal with this.