class User(models.Model):
name = models.CharField(max_length=255)
profile = models.OneToOneField('Profiles', null=True, blank=True, related_name='user_profile', on_delete=models.PROTECT)
class Profile(models.Model):
age = models.IntegerField(blank=False, null=False)
{% for user in object_list %}
User name: {{ user.name }}
age: {{ user.user_profile.age }}
{% end for %}
class UsersListView(ListView): # Страница поиска мастеров
model = User
template_name = "catalog/search-master.html"
paginate_by = 30
def save(self, commit=True):
instance = super(SawnetForm, self).save(commit=False)
# тут логика получения данных для сохранения в БД
if commit:
ReadySubnets.objects.update_or_create(
ip_net=self.cleaned_data['ip_lan_24'],
mask=self.cleaned_data['mask'],
)
return instance
These profile models are not special in any way - they are just Django models that happen to have a one-to-one link with a user model. As such, they aren’t auto created when a user is created, but a django.db.models.signals.post_save could be used to create or update related models as appropriate.
class AuthUser(AbstractBaseUser, PermissionsMixin):
email = models.EmailField(u'Электронная почта', unique=True)
date_add = models.DateTimeField(u'Дата добавлен', auto_now_add=True)
is_active = models.BooleanField(u'активен', default=True)
employee = models.OneToOneField('person.Employies', null=True, blank=True, editable=True, verbose_name='Профиль сотрудника', on_delete=models.PROTECT)
is_staff = models.BooleanField(u'администратор', default=False
, help_text=u'определяет возможность входа в панель управления')
roles = models.ManyToManyField(AuthUserRoles, verbose_name=u'Роли')
objects = AuthUserManager()
server {
listen 80;
server_name site.domain.ru;
charset utf-8;
error_log /usr/local/www/project/nginx_error.log;
client_max_body_size 15m;
location /robots.txt {
alias /usr/local/www/project/robots.txt;
}
location /media {
alias /usr/local/www/project/src/media; # your Django project's media files - amend as required
}
location /static {
alias /usr/local/www/project/static; # your Django project's static files - amend as required
}
location /mediashare {
alias /usr/local/www/project/mediashare; #
}
location / {
uwsgi_read_timeout 600;
uwsgi_send_timeout 600;
uwsgi_pass 127.0.0.1:5004;
include uwsgi_params;
add_header X-uri "$arg_page";
}
}
class CompanyCreatePrivateView(MultiFormCreate):
template_name = 'company/company_create_private.html'
formconf = {
'company': {'formclass': CompanyCreatePrivateForm},
'person': {'formclass': PersonCompanyCreateForm},
'phone': {'formclass': PhoneNumberMaskedCreateForm},
'companycontact': {'formclass': CompanyContactForm},
}
class AuthorDetailView(DetailView):
model = Author
template_name = 'catalog/author_detail.html'
def get_context_data(self, **kwargs):
context = super(AuthorDetailView, self).get_context_data(**kwargs)
context['author_books'] = Book.objects.filter(author=pk).values('title', 'summary')
return context