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>
...
...
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>
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)