Business
Jobs
  • About Us
  • Solutions
    • Job Postings
      Post your job and receive qualified candidates in 48h.
    • Candidate Assessments
      500+ technical and psychological tests, plus anti-fraud.
    • Headhunting
      Tailor-made executive search from start to finish.
    • Payroll + EOR
      Payroll dispersal and EOR across 15+ LATAM countries.
  • Pricing
  • Jobs

0

138
Views
Django need first paragraph

I created model with my posts. file blog/models.py:

import datetime

from ckeditor.fields import RichTextField
from django.db import models


class Post(models.Model):
    name = models.CharField(max_length=250)
    content = RichTextField()
    date = models.DateField(default=datetime.date.today)

and in db i has this record:

<p>First paragraph</p>

<p>Second paragraph</p>

<p>Third paragraph</p>

<p>etc</p>

<p>...</p>

How I can get result First paragraph ONLY

over 4 years ago · Santiago Trujillo
1 answers
Answer question

0

You could work with BeautifulSoup and make a property that will return the HTML content of the first paragraph. You first install beautifulsoup with:

pip3 install beautifulsoup4

then we can define a property that implements logic to extract the first <p> tag:

from bs4 import BeautifulSoup

class Post(models.Model):
    name = models.CharField(max_length=250)
    content = RichTextField()
    date = models.DateField(auto_now_add=True)

    def first_paragraph(self):
        bs = BeautifulSoup(self.content)
        return str(bs.find('p'))
over 4 years ago · Santiago Trujillo Report
Answer question
Find remote jobs

Discover the new way to find a job!

Top jobs
Top job categories
Business
Post vacancy Pricing Sales
Legal
Terms and conditions Privacy policy
© 2026 PeakU Inc. All Rights Reserved.
Andres GPT
Show me some job opportunities
There's an error!