Follow

Keep Up to Date with the Most Important News

By pressing the Subscribe button, you confirm that you have read and are agreeing to our Privacy Policy and Terms of Use
Contact

how to separate sentences and assign each sentence to a list element on template

how do I separate the list of strings by "." and render them into separate "li" elements on the template. Currently, it just displays everything in one "li" element. I would really appreciate it if someone can help, thx!

models.py

class Product(models.Model):
    benifits = ArrayField(models.CharField(max_length=800), blank=True)

    @property
    def benifits_slicing(self):
        benifit = self.benifits
        for point in benifit:
            test = point.split(".")
        return point

views.py

MEDevel.com: Open-source for Healthcare and Education

Collecting and validating open-source software for healthcare, education, enterprise, development, medical imaging, medical records, and digital pathology.

Visit Medevel

def described_view(request, slug):
    products = Product.objects.get(slug=slug)
    context = {"products": products}

HTML

<div id="BENIFITS">
    <li class="benifits-style">{{ products.benifits_slicing }}</li>
</div>

what it looks like rn:

enter image description here

>Solution :

You can try to do something like this…

class Product(models.Model):
    benifits = ArrayField(models.CharField(max_length=800), blank=True)

    @property
    def benifits_slicing(self):
        benifit = self.benifits
        data = []
        for point in benifit:
            data.extend(point.split("."))
        return data

HTML

<div id="BENIFITS">
    {% with data_benefit=products.benifits_slicing %}
    {% for data in data_benefit %}
    <li class="benifits-style">{{ data }}</li>
    {% endfor %}
    {% endwith %}
</div>
Add a comment

Leave a Reply

Keep Up to Date with the Most Important News

By pressing the Subscribe button, you confirm that you have read and are agreeing to our Privacy Policy and Terms of Use

Discover more from Dev solutions

Subscribe now to keep reading and get access to the full archive.

Continue reading