const rootReducer = combineReducers({
propsReducer: reducer
});
const mapStateToProps = state => ({
onLike: state.propReducer.like
});
{stateToPropsStartDataArray &&
Object.keys(stateToPropsStartDataArray).map(element => (
<button
data-stateToPropsCategory={element}
onClick={e =>
onFilter({
stateToPropsCategory: e.target.dataset.statetopropscategory
})
}
className={
element === stateToPropsCategory ? "active" : "noActive"
}
>
{element}
</button>
))}
var newData = state.startDataArray[
action.stateToPropsCategory || state.category
].filter(x => {
return x["planeTypeID.code"]
.toLowerCase()
.includes(action.search || state.searchInput);
});
componentDidMount() {
if (this.props.users.length === 0) {
// запрос к api
}
}
Your project will probably also have static assets that aren’t tied to a particular app. In addition to using a static/ directory inside your apps, you can define a list of directories (STATICFILES_DIRS) in your settings file where Django will also look for static files.
class Book(models.Model):
...
author = models.ForeignKey(Author, related_name="books", on_delete=models.SET_NULL, null=True)
...
def index(request):
context = {}
authors = Author.objects.all()
context['authors'] = authors
return render(request, 'index.html', context)
...
<div>
{% for author in authors %}
<h1>{{ author.first_name }}</h1>
{% for book in author.books.all %}
<h4>{{ book.title }}</h4>
{% empty %}
<p>Похоже, у этого автора нет книг :(</p>
{% endfor %}
{% endfor %}
</div>
...
The Element.clientWidth property is zero for inline elements
img is a replaced element; it has a display value of inline by default
...
bookmarks = Bookmark.all()
context['bookmarks'] = bookmarks
...
<span class="quiz__bookmarks ml-3">
{% for bookmark in bookmarks %}
{% if user in bookmark.user %}
<i class="fas fa-star bookmarked-star"></i>
{% else %}
<i class="far fa-star"></i>
{% endif %}
{% endfor %}
{{ quiz.get_bookmarks_count }}
</span>
import React, { Component, Fragment } from 'react';
import { connect } from 'react-redux';
import { personsFetchData } from '../Actions/persons';
// import { User, Headline, Paragraph, UserImage } from '../Website/Users/UsersStyles';
class PersonsData extends Component {
componentDidMount() {
this.props.fetchData('https://frontend-test-assignment-api.abz.agency/api/v1/users');
}
render() {
const { users } = this.props.persons;
return(
<Fragment>
{ users ? users.map(user => <div>{ user.name }</div>) : null }
</Fragment>
);
}
}
const mapStateToProps = state => ({
persons: state.persons.payload,
});
const mapDispatchToProps = dispatch => ({
fetchData: url => dispatch(personsFetchData(url)),
});
export default connect(mapStateToProps, mapDispatchToProps)(PersonsData);
STATIC_ROOT = BASE_DIR + '/static/'
STATIC_URL = '/static/'
MEDIA_ROOT = BASE_DIR + '/media/'
MEDIA_URL = '/media/'
from django.conf import settings
from django.conf.urls.static import static
urlpatterns += static(settings.STATIC_URL, document_root=settings.STATIC_ROOT)
urlpatterns += static(settings.MEDIA_URL, document_root=settings.MEDIA_ROOT)
class ProductsImage(models.Model): # Модель картинок товаров
products = models.ForeignKey(Product, related_name='prodimg', on_delete=models.CASCADE) # Связь один ко многим(внешний ключ товаров)
img = models.ImageField(upload_to='products/img/%Y/%m/%d') # Поле для загрузок картинок товаров
{% block content %}
{% for product in category.product_set.all %}
<div class="product">
<div class="title"
<a href="#">{{ product.name }}</a>
</div>
</div>
<div class="productImg">
<a href="#">
{% for prodimg in product.prodimg.all %}
<img src="{{ prodimg.img.url }}" alt="продукт">
{% endfor %}
</a>
</div>
{% endfor %}
{% endblock %}
many=true
в FiltersSerializers.class FiltersView(views.APIView):
def get(self, request, *args, **kwargs):
filters = {}
filters['model_1'] = Model1.objects.all()
filters['model_2'] = Model2.objects.all()
filters['model_3'] = Model3.objects.all()
serializer = FiltersSerializers(filters)
return Response (serializer.data, status=HTTP_200_OK)