# Анализ модального окна создания документов ## 📋 Проверка соответствия Модель → API → Модал → JavaScript --- ## ✅ **Модель Document** ### Поля модели (`documents/models.py`): ```python class Document(models.Model): title = models.CharField(max_length=255) # Обязательное file = models.FileField(upload_to='...') # Обязательное description = models.TextField(blank=True) # Необязательное uploaded_by = models.ForeignKey(...) # Автоматическое uploaded_at = models.DateTimeField(auto_now_add=True) # Автоматическое sent_to_all = models.BooleanField(default=True) # ✅ ИСПРАВЛЕНО: default=True departments = models.ManyToManyField(blank=True) # Необязательное recipients = models.ManyToManyField(blank=True) # Необязательное ``` **Изменения:** - ✅ `sent_to_all` изменен с `default=False` на `default=True` - ✅ Теперь соответствует HTML форме (checkbox checked по умолчанию) --- ## ✅ **API Serializer** ### DocumentWriteSerializer (`api/v1/documents/serializers.py`): ```python class DocumentWriteSerializer(serializers.ModelSerializer): recipient_ids = RecipientIDsField(write_only=True, required=False) department_ids = RecipientIDsField(write_only=True, required=False) class Meta: fields = ( "id", "title", "description", "file", "sent_to_all", "department_ids", "recipient_ids" ) ``` ### Валидация: ```python def validate(self, attrs): # При создании file обязателен if self.instance is None and not attrs.get("file"): raise ValidationError({"file": "Обязательное поле."}) # При sent_to_all=False требуются получатели ИЛИ отделы if not attrs.get("sent_to_all", True): if not attrs.get("recipient_ids") and not attrs.get("department_ids"): raise ValidationError({ "recipient_ids": "Укажите получателей, отделы или установите sent_to_all=true." }) return attrs ``` ### Поддерживаемые форматы для recipient_ids и department_ids: - ✅ Repeat-params: `?recipient_ids=1&recipient_ids=2&recipient_ids=3` - ✅ JSON: `recipient_ids: "[1,2,3]"` - ✅ CSV: `recipient_ids: "1,2,3"` --- ## ✅ **HTML Модальное окно** ### Форма создания (`templates/documents/document_list.html`): ```html