сделал отображение фотографии пользователя и админку для пользователей
This commit is contained in:
parent
55921d3da0
commit
50d00cecba
1
.gitignore
vendored
1
.gitignore
vendored
@ -144,3 +144,4 @@ cython_debug/
|
||||
/.prod/
|
||||
/.test/
|
||||
/er.txt
|
||||
/Документы/Странички.drawio
|
||||
|
||||
@ -119,7 +119,7 @@ MEDIA_URL = "/media/"
|
||||
|
||||
MEDIA_ROOT = BASE_DIR / "media"
|
||||
|
||||
LOGIN_URL = "/users/login/"
|
||||
LOGIN_URL = "/auth/login/"
|
||||
|
||||
LOGIN_REDIRECT_URL = "/"
|
||||
|
||||
|
||||
@ -14,6 +14,10 @@ urlpatterns = [
|
||||
]
|
||||
|
||||
urlpatterns += static(settings.STATIC_URL, document_root=settings.STATIC_ROOT)
|
||||
urlpatterns += static(
|
||||
settings.MEDIA_URL,
|
||||
document_root=settings.MEDIA_ROOT,
|
||||
)
|
||||
|
||||
if settings.DEBUG:
|
||||
import debug_toolbar
|
||||
|
||||
@ -1,3 +1,24 @@
|
||||
from django.contrib import admin
|
||||
from django.contrib.auth import get_user_model
|
||||
from django.contrib.auth.admin import UserAdmin
|
||||
|
||||
# Register your models here.
|
||||
from users.models import Profile
|
||||
|
||||
user = get_user_model()
|
||||
admin.site.unregister(user)
|
||||
|
||||
|
||||
class ProfileInline(admin.TabularInline):
|
||||
can_delete = False
|
||||
model = Profile
|
||||
fields = [
|
||||
Profile.birthday.field.name,
|
||||
Profile.image.field.name,
|
||||
]
|
||||
|
||||
|
||||
@admin.register(user)
|
||||
class UserAdmin(UserAdmin):
|
||||
inlines = [
|
||||
ProfileInline,
|
||||
]
|
||||
|
||||
@ -1,10 +1,12 @@
|
||||
import time
|
||||
|
||||
from django.db.models import (
|
||||
Model,
|
||||
CharField,
|
||||
IntegerField,
|
||||
DateField,
|
||||
ManyToManyField,
|
||||
Manager,
|
||||
Manager, ImageField,
|
||||
)
|
||||
from django.utils import timezone
|
||||
from django.core.validators import MinValueValidator
|
||||
@ -32,6 +34,9 @@ class Genre(Model):
|
||||
|
||||
|
||||
class Film(Model):
|
||||
def get_upload_path(self, filename):
|
||||
return f'users/avatars/{self.pk}/{time.time()}_{filename}'
|
||||
|
||||
objects = FilmManager()
|
||||
|
||||
name = CharField(
|
||||
@ -59,6 +64,13 @@ class Film(Model):
|
||||
null=False,
|
||||
)
|
||||
|
||||
image = ImageField(
|
||||
null=True,
|
||||
blank=True,
|
||||
verbose_name='Аватар пользователя',
|
||||
upload_to=get_upload_path,
|
||||
)
|
||||
|
||||
genres = ManyToManyField(
|
||||
Genre,
|
||||
verbose_name='Жанры',
|
||||
|
||||
@ -3,4 +3,12 @@
|
||||
}
|
||||
body {
|
||||
background-color: #0d1d3a;
|
||||
}
|
||||
html::-webkit-scrollbar {
|
||||
width: 0.8vw;
|
||||
}
|
||||
html::-webkit-scrollbar-thumb {
|
||||
background-color: #eaeaea;
|
||||
border-radius: 5vw;
|
||||
border: 4px solid #0d1d3a;
|
||||
}
|
||||
@ -7,7 +7,6 @@
|
||||
<meta name="viewport" content="width=device-width, initial-scale=1.0">
|
||||
<title>{% block title %}{% endblock title %}</title>
|
||||
<link href="{% static 'css/bootstrap/bootstrap.min.css' %}" rel="stylesheet">
|
||||
<link rel="stylesheet" href="{% static 'css/header.css' %}"/>
|
||||
<!--<link rel="stylesheet" href="{% static 'css/footer.css' %}"/>-->
|
||||
<link rel="apple-touch-icon" sizes="180x180" href="{% static 'img/apple-touch-icon.png' %}">
|
||||
<link rel="icon" type="image/png" sizes="32x32" href="{% static 'img/favicon-32x32.png' %}">
|
||||
|
||||
@ -13,6 +13,6 @@
|
||||
{% endif %}
|
||||
</div>
|
||||
{% endfor %}
|
||||
<button type="submit" class="btn btn-primary">{% if text_button %} {{ text_button }} {% else %} отправить {% endif %}
|
||||
<button type="submit" class="btn btn-primary">{% if text_button %} {{ text_button }} {% else %} Отправить {% endif %}
|
||||
</button>
|
||||
</form>
|
||||
|
||||
@ -24,8 +24,8 @@
|
||||
{% if user.is_authenticated %}
|
||||
<a class="user_link" href="{% url 'users:profile' %}">{{ user }}</a>
|
||||
<a class="user_link" href="{% url 'users:profile' %}">
|
||||
{% if user.image %}
|
||||
{{ user.image_tmb }}
|
||||
{% if user.profile.image %}
|
||||
<img src="{{ user.profile.image.url }}" class="header_icon col-4">
|
||||
{% else %}
|
||||
<img src="{% static 'img/user.png' %}" class="header_icon col-4">
|
||||
{% endif %}
|
||||
|
||||
@ -45,7 +45,7 @@
|
||||
{% endif %}
|
||||
<button class="btn btn-primary" type="submit">Сохранить изменения</button>
|
||||
</form>
|
||||
<a class="btn btn-primary" type="submit" href="{% url 'users:logout' %}">Выйти</a>
|
||||
<a class="btn btn-danger" type="submit" href="{% url 'users:logout' %}">Выйти</a>
|
||||
<a href="{% url "users:password_change" %}">Сменить пароль</a>
|
||||
{% endblock content %}
|
||||
</div>
|
||||
@ -8,6 +8,7 @@ from django.contrib.auth.forms import (
|
||||
UserChangeForm,
|
||||
UserCreationForm,
|
||||
)
|
||||
from django.forms import DateInput
|
||||
|
||||
from users.models import Profile
|
||||
|
||||
@ -76,6 +77,9 @@ class ProfileForm(forms.ModelForm):
|
||||
model.birthday.field.name,
|
||||
model.image.field.name,
|
||||
]
|
||||
widgets = {
|
||||
model.birthday.field.name: DateInput(attrs={'type': 'date'})
|
||||
}
|
||||
|
||||
|
||||
class CustomUserChangeForm(UserChangeForm):
|
||||
|
||||
@ -19,6 +19,9 @@ urlpatterns = [
|
||||
views.LoginView.as_view(
|
||||
template_name='users/login.html',
|
||||
authentication_form=CustomAuthenticationForm,
|
||||
extra_context={
|
||||
'text_button': 'Войти',
|
||||
},
|
||||
),
|
||||
name='login',
|
||||
),
|
||||
|
||||
@ -42,21 +42,12 @@ def profile(request):
|
||||
request.POST or None,
|
||||
instance=request.user,
|
||||
)
|
||||
if request.method == 'GET':
|
||||
return render(
|
||||
request,
|
||||
'users/profile.html',
|
||||
{
|
||||
'profile_form': profile_form,
|
||||
'user_form': user_form,
|
||||
'user': request.user,
|
||||
'text_button': 'Войти',
|
||||
},
|
||||
)
|
||||
|
||||
if all((profile_form.is_valid(), user_form.is_valid())):
|
||||
profile_form.save()
|
||||
user_form.save()
|
||||
if request.method == 'POST':
|
||||
if all((profile_form.is_valid(), user_form.is_valid())):
|
||||
profile_form.save()
|
||||
user_form.save()
|
||||
return redirect(reverse('users:profile'))
|
||||
|
||||
return render(
|
||||
request,
|
||||
|
||||
Loading…
x
Reference in New Issue
Block a user