from django.db import models
from django.contrib.auth.models import User
class Profile(models.Model):
user = models.ForeignKey(User, on_delete=models.CASCADE, related_name='user')
city = models.CharField(max_length=100, blank=True, null=True)
site = models.CharField(max_length=100, blank=True, null=True)
day_of_birth = models.DateTimeField(null=True, blank=True)
phonenumber = models.CharField(max_length=35, blank=True, null=True)
class Meta:
db_table = 'Profile'
def moderation_page(request, pk):
non_active_news = News.objects.order_by('-created').filter(status=3)
non_verified_users = User.objects.filter(groups=5)
profiles = Profile.objects.all()
context = {
'non_active_news': non_active_news,
'non_verified_users': non_verified_users,
'profiles': profiles,
}
return render(request, 'users/moderation.html', context)
<table class="non_ver_users-table">
<thead class="non_ver_users-table-row thead">
<td class="non_ver_users-table-item">Логин</td>
<td class="non_ver_users-table-item">Дата создания</td>
<td class="non_ver_users-table-item">Номер телефона</td>
<td class="non_ver_users-table-item">E-mail</td>
<td class="non_ver_users-table-item">Статус</td>
</thead>
<tbody class="non_ver_users-table-row"></tbody>
{% for user in non_verified_users %}
<tr>
<td class="non_ver_users-table-item">{{ user.username }}</td>
<td class="non_ver_users-table-item">{{ user.date_joined }}</td>
<td class="non_ver_users-table-item">{{ profile.user.phonenumber }}</td>
<td class="non_ver_users-table-item">{{ user.email }}</td>
<td class="non_ver_users-table-item">{{ }}</td>
</tr>
{% endfor %}
</table>
from django.contrib.auth.models import AbstractUser
class CustomUser(AbstractUser):
code = models.IntegerField(verbose_name="Код", blank=True, null=True)
is_salesman = models.BooleanField(default = False, verbose_name="Продавец")
age = models.IntegerField(verbose_name="Возраст", blank=True, null=True)
number_of_phone = models.CharField(max_length=13,verbose_name="Номер телефона", blank=True, null=True)
city = models.CharField(max_length=64, verbose_name="Населенный пункт", blank=True, null=True)
company = models.CharField(max_length=64, verbose_name="Компания", default="company name", blank=True, null=True)
AUTH_USER_MODEL = 'your_app_name.CustomUser'
{{ user.number_of_phone }}
...
profile = Profile.objects.get(user = request.user)
...