Итак, дело в том, что я добавил пользовательскую модель пользователя
models.py
class CustomUserModel(AbstractUser):
pass
Morasko = "Morasko"
Piatkowo = "Piątkowo"
district_choices = [
(Morasko, "Morasko"),
(Piatkowo, "Piątkowo"),
]
district = models.CharField(max_length=15, choices=district_choices, default=district_choices[0])
Поле 'округ' должно быть полем выбора с двумя вариантами. Вот пользовательская форма регистрации, которую я использую.
forms.py
class NewUserForm(UserCreationForm):
district = forms.ChoiceField(widget=forms.RadioSelect, choices=CustomUserModel.district_choices)
class Meta(UserCreationForm):
model = CustomUserModel
fields = ('username', 'email', 'district', 'password1', 'password2')
def save(self, commit=True):
user = super(NewUserForm, self).save(commit=False)
user.email = self.cleaned_data['email']
user.district = self.cleaned_data['district']
if commit:
user.save()
return user
Мой html файл регистрации:
register.html
{% extends "map_neigh/home.html" %}
{% block content %}
<div class='container'>
<div id='inner'>
<br>
<form method="POST">
{% csrf_token %}
{{form.as_p}}
<button class="btn btn-primary" type="submit">Register</button>
</form>
<br>
<br>
If you already have an account <a href="/login"><strong>log in.</strong></a>
</div>
</div>
{% endblock %}
Поле выбора действительно работает - пользователи сохраняются в БД с выбранным районом, но выглядят неактивнымии я понятия не имею, почему. Нажатие на нее не меняет внешний вид, если я наведу указатель мыши на один из параметров, не изменится ни тот, ни другой. Ниже скриншот формы регистрации. ![As you can see hove does not work, clicking doesn't change anything neither](https://i.stack.imgur.com/AaRNd.png)
home.html
<!DOCTYPE html>
<html>
<head>
<meta charset='utf-8' />
<title>NoFence</title>
{% load static %}
<meta name='viewport' content='initial-scale=1,maximum-scale=1,user-scalable=no' />
<link rel = "stylesheet" type = "text/css" href = "{% static 'style.css' %}"/>
<!--bootstrap-->
<link rel="stylesheet" href="https://maxcdn.bootstrapcdn.com/bootstrap/4.0.0/css/bootstrap.min.css" integrity="sha384-Gn5384xqQ1aoWXA+058RXPxPg6fy4IWvTNh0E263XmFcJlSAwiGgFAW/dAiS6JXm" crossorigin="anonymous">
<link rel="stylesheet" href="https://maxcdn.bootstrapcdn.com/font-awesome/4.7.0/css/font-awesome.min.css">
<!--jQuery links -->
<script src="https://ajax.googleapis.com/ajax/libs/jquery/1.7.1/jquery.min.js"></script>
<script src="https://code.jquery.com/jquery-1.7.1.min.js"></script>
<!--leaflet links -->
<link rel="stylesheet" href="http://cdn.leafletjs.com/leaflet/v0.7.7/leaflet.css" />
<script src="http://cdn.leafletjs.com/leaflet/v0.7.7/leaflet.js"></script>
<link rel="stylesheet" href="https://cdn.jsdelivr.net/npm/leaflet.locatecontrol@0.65.2/dist/L.Control.Locate.min.css" />
<script src="https://cdn.jsdelivr.net/npm/leaflet.locatecontrol@0.65.2/src/L.Control.Locate.min.js" charset="utf-8"></script>
<!--toast-->
<link rel="stylesheet" href="https://cdnjs.cloudflare.com/ajax/libs/materialize/1.0.0/css/materialize.min.css">
<script src="https://cdnjs.cloudflare.com/ajax/libs/materialize/1.0.0/js/materialize.min.js"></script>
<!--jquery scripts -->
<script>
</script>
</head>
<body>
<!--navigation bar-->
{% include "map_neigh/includes/navbar.html" %}
<!--user messages-->
{% include "map_neigh/includes/messaging.html" %}
{% block content %}
{% endblock %}
</body>
</html>
style.css
body {
margin:0;
padding:0;
background-color:#808080;
}
#menu_res {
position: relative;
padding-left: 15%;
font-size: 1.25vw;
}
#menu {
position: relative;
padding-left: 15%;
padding-top: 1.5vw;
padding-bottom: 0.9vw;
font-size: 1.5vw;
}
html{
scroll-behavior: smooth;
}
#inner {
width: 50%;
margin: 0 auto;
}