починил ввод данных в профиле
This commit is contained in:
parent
bb6d57cf17
commit
eb16203995
@ -9,6 +9,7 @@ class FilmAdmin(admin.ModelAdmin):
|
|||||||
list_display = [
|
list_display = [
|
||||||
Film.name.field.name,
|
Film.name.field.name,
|
||||||
Film.duration.field.name,
|
Film.duration.field.name,
|
||||||
|
Film.image.field.name,
|
||||||
'get_image',
|
'get_image',
|
||||||
]
|
]
|
||||||
|
|
||||||
@ -21,6 +22,10 @@ class FilmAdmin(admin.ModelAdmin):
|
|||||||
Film.actors.field.name,
|
Film.actors.field.name,
|
||||||
]
|
]
|
||||||
|
|
||||||
|
list_editable = [
|
||||||
|
Film.image.field.name,
|
||||||
|
]
|
||||||
|
|
||||||
def get_image(self, obj):
|
def get_image(self, obj):
|
||||||
return mark_safe(
|
return mark_safe(
|
||||||
f"<img src='{obj.image_tmb()}' width='50' height='50'",
|
f"<img src='{obj.image_tmb()}' width='50' height='50'",
|
||||||
|
|||||||
@ -2,6 +2,7 @@ import time
|
|||||||
from datetime import timedelta
|
from datetime import timedelta
|
||||||
|
|
||||||
import sorl
|
import sorl
|
||||||
|
from django.core.validators import MinValueValidator
|
||||||
from django.db.models import (
|
from django.db.models import (
|
||||||
Model,
|
Model,
|
||||||
CharField,
|
CharField,
|
||||||
@ -9,10 +10,8 @@ from django.db.models import (
|
|||||||
DateField,
|
DateField,
|
||||||
ManyToManyField,
|
ManyToManyField,
|
||||||
Manager, ImageField, Min,
|
Manager, ImageField, Min,
|
||||||
ForeignKey, CASCADE,
|
|
||||||
)
|
)
|
||||||
from django.utils import timezone
|
from django.utils import timezone
|
||||||
from django.core.validators import MinValueValidator
|
|
||||||
from django.utils.safestring import mark_safe
|
from django.utils.safestring import mark_safe
|
||||||
from sorl.thumbnail import get_thumbnail
|
from sorl.thumbnail import get_thumbnail
|
||||||
|
|
||||||
|
|||||||
@ -47,5 +47,5 @@
|
|||||||
</form>
|
</form>
|
||||||
<a class="btn btn-danger" 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 %}
|
|
||||||
</div>
|
</div>
|
||||||
|
{% endblock content %}
|
||||||
@ -1,5 +1,6 @@
|
|||||||
from django import forms
|
from django import forms
|
||||||
from django.contrib.auth import get_user_model
|
from django.contrib.auth import get_user_model
|
||||||
|
from django.forms import DateInput, ModelForm
|
||||||
from django.contrib.auth.forms import (
|
from django.contrib.auth.forms import (
|
||||||
AuthenticationForm,
|
AuthenticationForm,
|
||||||
PasswordChangeForm,
|
PasswordChangeForm,
|
||||||
@ -8,7 +9,6 @@ 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
|
||||||
|
|
||||||
@ -65,18 +65,21 @@ class SignUpForm(UserCreationForm):
|
|||||||
fields = ('username', 'email')
|
fields = ('username', 'email')
|
||||||
|
|
||||||
|
|
||||||
class ProfileForm(forms.ModelForm):
|
class ProfileForm(ModelForm):
|
||||||
def __init__(self, *args, **kwargs) -> None:
|
def __init__(self, *args, **kwargs) -> None:
|
||||||
super().__init__(*args, **kwargs)
|
super().__init__(*args, **kwargs)
|
||||||
for field in self.visible_fields():
|
for field in self.visible_fields():
|
||||||
field.field.widget.attrs['class'] = 'form-control'
|
field.field.widget.attrs['class'] = 'form-control'
|
||||||
|
|
||||||
class Meta(forms.ModelForm):
|
class Meta(ModelForm):
|
||||||
model = Profile
|
model = Profile
|
||||||
fields = [
|
fields = [
|
||||||
model.birthday.field.name,
|
model.birthday.field.name,
|
||||||
model.image.field.name,
|
model.image.field.name,
|
||||||
]
|
]
|
||||||
|
widgets = {
|
||||||
|
'birthday': DateInput(attrs={'type': 'date'}, format='%Y-%m-%d'),
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
class CustomUserChangeForm(UserChangeForm):
|
class CustomUserChangeForm(UserChangeForm):
|
||||||
|
|||||||
@ -36,6 +36,7 @@ def signup(request):
|
|||||||
def profile(request):
|
def profile(request):
|
||||||
profile_form = ProfileForm(
|
profile_form = ProfileForm(
|
||||||
request.POST or None,
|
request.POST or None,
|
||||||
|
request.FILES or None,
|
||||||
instance=request.user.profile,
|
instance=request.user.profile,
|
||||||
)
|
)
|
||||||
user_form = UserForm(
|
user_form = UserForm(
|
||||||
@ -58,3 +59,4 @@ def profile(request):
|
|||||||
'user': request.user,
|
'user': request.user,
|
||||||
},
|
},
|
||||||
)
|
)
|
||||||
|
|
||||||
|
|||||||
Loading…
x
Reference in New Issue
Block a user