Server-side implementation of instagram-like tags
<p>I'm looking for some pythonic way to implement instagram-like tags functionality.</p>

<p>Let's suppose my Tag Model is:</p>

<pre><code>class Tag(models.Model):
    slug = models.SlugField(max_length=120, unique=True)
    products = models.ManyToManyField(Product)

    def get_absolute_url(self):
        return reverse("tags:detail", kwargs={"slug": self.slug})
</code></pre>

<p>And Comment Model is:</p>

<pre><code>class Comment(models.Model):
    text = models.TextField(max_length=350)
    user = models.ForeignKey(settings.AUTH_USER_MODEL)
    product = models.ForeignKey(Product)
    timestamp = models.DateTimeField(auto_now_add=True, auto_now=False)
</code></pre>

<p>What's the best way to implement addition of links inside CharField so that the message code  of comment "Some sort of cool stackoverflow comment" 
would look like this:</p>

<pre><code>&lt;p&gt;
Some sort of &lt;a href="{% url "tags:detail" kwargs={"slug": "cool"}
%}"&gt;#cool&lt;/a&gt; &lt;a href="{% url "tags:detail" kwargs={"slug": "stackoverflow"} %}"&gt;#stackoverflow&lt;/a&gt; comment
&lt;/p&gt;
</code></pre>

<p>I would suggest use of another model to link the Tags to the Comments. This model will have the tag and comment both as Many to Many relations. Now this model can be used to establish relations and perform operations. Rest depends on your logic, how well you use this model.</p>

python django