diff --git a/areas/forms.py b/areas/forms.py index 1646bc3..748b855 100644 --- a/areas/forms.py +++ b/areas/forms.py @@ -6,7 +6,6 @@ from dal import autocomplete from django.contrib.auth.models import User from django import forms - class AreaAddAreaForm(forms.ModelForm): class Meta: @@ -14,9 +13,15 @@ class AreaAddAreaForm(forms.ModelForm): labels = { "name" : "Bereichsname", "color" : "Farbe", - "desc" : "Kurze Beschreibung" - } - fields = ['name', 'color', 'desc'] + "desc" : "Kurze Beschreibung", + "usersfield" : "Zugeteilte Personen" + } + fields = ['name', 'color', 'desc', 'usersfield'] + def __init__(self, user, *args, **kwargs): + super().__init__(*args, **kwargs) - \ No newline at end of file + users_of_agency = User.objects.filter(profile__agency__pk=user.profile.agency.pk) + print(users_of_agency) + print(self.fields['usersfield']) + self.fields['usersfield'].queryset = users_of_agency \ No newline at end of file diff --git a/areas/models.py b/areas/models.py index 8bf8b27..7a52b58 100644 --- a/areas/models.py +++ b/areas/models.py @@ -5,7 +5,6 @@ from colorful.fields import RGBColorField from django.contrib.auth.models import User import datetime - ''' Model Areas @@ -24,9 +23,7 @@ class Areas(models.Model): name = models.CharField(max_length=200, blank=False) color = RGBColorField(colors=['#FFB900', '#E74856', '#0078D7', '#0099BC', '#7A7574'], default='#0099BC', blank=True) desc = models.TextField(max_length=3000, blank=True) - #usersfield = MultiSelectField(choices=(()), blank=True) - #usersfield = forms.ModelMultipleChoiceField(queryset=User.objects.all()) - #usersfield = forms.ModelChoiceField(queryset=User.objects.filter(profile__pk=1)) + usersfield = models.ManyToManyField(User, blank=True, related_name='users_in_area') created_area_by = models.ForeignKey(User, on_delete=models.PROTECT) created_area_date = models.DateField(default=datetime.date.today, blank=True) diff --git a/areas/templates/areas/areas_update.html b/areas/templates/areas/areas_update.html index c7d74ab..0e9c344 100644 --- a/areas/templates/areas/areas_update.html +++ b/areas/templates/areas/areas_update.html @@ -1,12 +1,13 @@ {% extends "users/base.html" %} +{% load static %} {% load crispy_forms_tags %} {% block content %}