The model has a "content" field. When changing this model, it is necessary to look for the symbol <a
in the content
field and add the line rel="nofollow"
into it (as if in a tag). I’m trying to do this with a function in the models.py file. Tell me how to do this ?
The save function for this model:
def save(self, *args, **kwargs):
if (self.original_price
and not isinstance(self.original_price, Decimal)):
self.original_price = Decimal(self.original_price)
if self.parent_id is not None and self.parent_id == 0:
self.parent = None
# Если товар не доступен для заказа, то amount_europe и
# amount_moscow считаем что не заданы
if self.amount_free == 0:
self.amount_europe = None
self.amount_moscow = None
if self._state.adding:
self.sort_order = 0
if self.content:
self.content = self.content.replace('\n', '<br>')
if '<a ' in self.content or '<iframe ' in self.content:
self.content = re.sub(r'<.*?>', '', self.content,
flags=re.IGNORECASE)
# Устанавливаем цену для сортировки
self.price_ordering = self.get_price()
super().save(*args, **kwargs)