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