@Index({ fulltext: true })
и использовать построитель запросов для написания собственного пользовательского запроса пользовательского запроса и использовать специальный синтаксис sql.@Entity()
export class User {
@PrimaryGeneratedColumn()
id: number;
@Index({ fulltext: true })
@Column("varchar")
name: string;
@Index({ fulltext: true })
@Column("varchar")
lastname: string;
@Index({ fulltext: true })
@Column("text")
personalDescription: string;
}
const searchTerm = "programmer";
const result = await connection.manager.getRepository(User)
.createQueryBuilder()
.select()
.where('MATCH(lastname) AGAINST ('${searchTerm}' IN BOOLEAN MODE)')
.orWhere('MATCH(name) AGAINST ('${searchTerm}' IN BOOLEAN MODE)')
.orWhere('MATCH(personalDescription) AGAINST ('${searchTerm}' IN BOOLEAN MODE)')
.getMany();
jQuery(document).ready(function () {
$('.modal').on('hidden.bs.modal', function (e) {
$(this).removeData('bs.modal');
});
});
$('.open-modal-btn').on('click', function (e) {
e.preventDefault();
var $content = $(this).parents('.cf7-section').find('.cf7-content').html();//получаем родителя и ищем в нем контент
$('#call-to-action').find('.modal-content-wrapper').html($content); //в модалке ищем место для вставки
var $target = $(this).attr('data-target');
openModal($target);
});
const childElements = photos.map(photo => (
<li className="list-unstyled">
<Link to={`/${photo.id}`}>
<img
className={`rounded ${ hovered === photo.id ? 'hover-class' : '' }`}
style={styles}
src={photo.urls.small}
alt={photo.description}
onMouseOut={() => {
setHovered(null)
}}
onMouseOver={() => {
setHovered(photo.id)
}}
/>
</Link>
</li>
))
import React, { useEffect, useRef, useState} from "react";
const defaultStyle = {
display: "block",
overflow: "hidden",
resize: "none",
width: "100%",
backgroundColor: "mediumSpringGreen"
};
const AutoHeightTextarea = ({ style = defaultStyle, ...etc }) => {
const textareaRef = useRef(null);
const [currentValue, setCurrentValue ] = useState("");
useEffect(() => {
textareaRef.current.style.height = "0px";
const scrollHeight = textareaRef.current.scrollHeight;
textareaRef.current.style.height = scrollHeight + "px";
}, [currentValue]);
return (
<textarea
ref={textareaRef}
style={style}
{...etc}
value={currentValue}
onChange={e=>setCurrentValue(e.target.value)}
/>
);
};
export default AutoHeightTextarea;
class XXX extends React.Component {
state = {
token: null
}
static getDerivedStateFromProps( props ){
if( props.token){
return {
token: props.token
}
}
return null;
}
}
{{ some_date|naturaltime|safe }}
import hashlib
import os
from django.conf import settings
from django.core.files.storage import FileSystemStorage
from django.db import models
def upload_to(instance, filename, fieldname):
ext = os.path.splitext(filename)[1].lower()
class_name = instance.__class__.__name__.lower()
h = hashlib.sha256()
field = getattr(instance, fieldname)
for chunk in field.chunks():
h.update(chunk)
name = h.hexdigest()
return os.path.join(
class_name,
name + ext,
)
class OverwriteStorage(FileSystemStorage):
def get_available_name(self, name, max_length=None):
if self.exists(name):
os.remove(os.path.join(settings.MEDIA_ROOT, name))
return name
class Article(models.Model):
image = models.ImageField(
storage=OverwriteStorage(),
upload_to=lambda inst, fn: upload_to(inst, fn, 'image'),
)
pip install django-hashedfilenamestorage
DEFAULT_FILE_STORAGE = 'django_hashedfilenamestorage.storage.HashedFilenameFileSystemStorage'
class App extends React.Component {
state = {
classes: [ 'bullshit' ],
}
onFocus = () => {
this.setState(({ classes }) => ({
classes: [ ...classes, 'focus' ],
}));
}
onBlur = () => {
this.setState(({ classes }) => ({
classes: classes.filter(n => n !== 'focus'),
}));
}
render() {
return (
<div className={this.state.classes.join(' ')}>
<input onFocus={this.onFocus} onBlur={this.onBlur} />
</div>
);
}
}
let searchBar = document.querySelector('.search'),
searchInput = searchBar.querySelector('input'),
searchToggleBtn = document.querySelector('.search-toggle'),
searchParent = document.querySelector('.header_content');
searchInput.addEventListener('focus', function (event) {
searchBar.classList.add('expanded');
});
searchInput.addEventListener('blur', function (event) {
searchInput.value || searchBar.classList.remove('expanded');
});
searchToggleBtn.addEventListener('click', function (event) {
searchToggleBtn.classList.toggle('active');
searchParent.classList.toggle('search');
searchBar.classList.toggle('visible');
searchInput.focus();
});
<Router />
компонента (или не из обертки withRouter).componentDidMount() {
if (this.props.match && this.props.match.params.postID) {
const postID = this.props.match.params.postID
axios.get(`http://127.0.0.1:8000/api/${postID}`)
.then(res => {
this.setState({
post: res.data
});
})
}
// если надо можете сделать else
}