class UserLevelAdmin(admin.ModelAdmin):
list_display = ('id', 'level', 'user', 'progress')
admin.site.register(UserLevel, UserLevelAdmin)
AUTH_USER_MODEL = 'accounts.User'
context = {'films': films, 'paginator': paginator}
from django.conf import settings
from django.conf.urls.static import static
urlpatterns = [
# ... the rest of your URLconf goes here ...
] + static(settings.MEDIA_URL, document_root=settings.MEDIA_ROOT)
def application_detail(request, pk):
application = get_object_or_404(Application, pk=pk)
return render(request, 'helpdesk/application_detail.html', {'application': application})
<li>Исполнитель(и): {% for executor in application.executor_set.all %}{{ executor.owner.get_full_name }}{% if not forloop.last %}, {%endif %}{% endfor %}
from django.urls import include, re_path
urlpatterns = [
re_path(r'^(?P<catalog>\w+)/$', views.catalog_view, name='catalog'),
re_path(r'^(?P<catalog>\w+)/(?P<brand>\w+)/$', views.brand_view, name='brand'),
re_path(r'^(?P<catalog>\w+)/(?P<brand>\w+)/(?P<product>\w+)/$', views.product_view, name='product'),
...
]
def product_view(request, catalog, brand, product):
# ...
class ImagesForSliderSerializer(serializers.ModelSerializer):
class Meta:
model = ImagesForSlider
fields = ('id', 'image', 'image_name')
class GroupSerializer(serializers.ModelSerializer):
images_for_slider = ImagesForSliderSerializer(many=True)
class Meta:
model = Group
fields = (
# ...
'images_for_slider',
)
class AdvertDetailView(DetailView):
model = Advert
template_name = "advert/_detail.html"
context_object_name = "advert"
def get_context_data(self, **kwargs):
context = super().get_context_data(**kwargs)
advert_fields = []
for field in self.model._meta.fields:
advert_fields.append((field.verbose_name, str(getattr(self.object, field.name))))
context['advert_fields'] = advert_fields
return context
<ul>
{% for verbose_name, value in advert_fields %}
<li>{{ verbose_name }} -> {{ value }}</li>
{% endfor %}
</ul>
_band_form = BandForm(request.POST, instance=user)
- здесь задается instance модели User, а нужен Band.user = User()
- несохраненный инстанс юзера бесполезно указывать как ForeignKey для Band. Необходимо его самого сначала сохранить