1👍
✅
Declare a class method like this:
class Post(models.Model):
actualPost = models.CharField(max_length=200)
def get_link(self):
if self.actualPost and '@' in self.actualPost:
return self.actualPost.split('@', 1)[1]
return None
and in the template
{% for post in post_list %}
{% if post.get_link %}
<a href="/{{ post.get_link }}/">Blah </a>
{% endif %}
{% endfor %}
Source:stackexchange.com