jazzband/django-taggit

Add support for initialising tags via a list on object creation

waveywhite opened this issue · 1 comments

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

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.