Я хочу показать пользователей, которые выбрали определенную роль, в выпадающем списке в другой форме,
ЛИЧНЫЕ ДАННЫЕ
user = models.ForeignKey(User,on_delete=models.CASCADE,default=1)
image = models.FileField(_('Profile Image'),upload_to='profiles',default='default.png',blank=True,null=True,help_text='upload image size less than 2.0MB')#work on path username-date/image
firstname = models.CharField(_('Firstname'),max_length=125,null=False,blank=False)
lastname = models.CharField(_('Lastname'),max_length=125,null=False,blank=False)
# linemanager = models.CharField(_('Line manager'),max_length=125,null=False,blank=False,default='mr.....')
# birthday = models.DateField(_('Birthday'),blank=False,null=False)
phone = models.CharField(_('Phone number'),max_length=12,null=False,blank=False,help_text='enter phone number')
department = models.ForeignKey(Department,verbose_name =_('Department'),on_delete=models.SET_NULL,null=True,default=None)
role = models.ForeignKey(Role,verbose_name =_('Role'),on_delete=models.SET_NULL,null=True,default=None)
это сотрудник models.py, где я добавляю сотрудников и выбираю определенную роль
def dashboard_employees_create(request): if not (request.user.is_authenticated and request.user.is_superuser and request.user.is_staff): return redirect('/')
if request.method == 'POST':
form = EmployeeCreateForm(request.POST,request.FILES)
if form.is_valid():
instance = form.save(commit = False)
user = request.POST.get('user')
assigned_user = User.objects.get(id = user)
instance.user = assigned_user
instance.title = request.POST.get('title')
instance.image = request.FILES.get('image')
instance.firstname = request.POST.get('firstname')
instance.lastname = request.POST.get('lastname')
instance.phone = request.POST.get('phone')
role = request.POST.get('role')
role_instance = Role.objects.get(id = role)
instance.role = role_instance
instance.startdate = request.POST.get('startdate')
instance.employeetype = request.POST.get('employeetype')
instance.employeeid = request.POST.get('employeeid')
# instance.dateissued = request.POST.get('dateissued')
instance.save()
Виды
class LeaveCreationForm(forms.ModelForm): reason = forms.CharField(required=False, widget=forms.Textarea(attrs={'rows': 4, 'cols': 40})) class Meta: model = Leave exclude = ['user','defaultdays','hrcomments','status','is_approved','updated','created']
Вот как выглядит моя форма создания отпуска