Commit 4d88cd6846e4b0cdb316312bd44a2a82705cb462
1 parent
9ed7eb11
Add handling unique name and sequence constraint during changing the models
Showing
2 changed files
with
11 additions
and
4 deletions
collector/storage/models.py
... | ... | @@ -147,9 +147,9 @@ class Document(models.Model): |
147 | 147 | class Meta: |
148 | 148 | db_table = 'document' |
149 | 149 | ordering = ['id'] |
150 | - # constraints = [ | |
151 | - # models.UniqueConstraint(fields=['name', 'sequence'], name='unique subdocument sequence') | |
152 | - # ] | |
150 | + constraints = [ | |
151 | + models.UniqueConstraint(fields=['name', 'sequence'], name='unique subdocument sequence') | |
152 | + ] | |
153 | 153 | |
154 | 154 | def __str__(self): |
155 | 155 | return f'{self.name}-{self.id}' |
... | ... |
collector/storage/views.py
... | ... | @@ -1158,7 +1158,8 @@ def change_doc_type(doc, target_type): |
1158 | 1158 | processing_status=doc.processing_status, |
1159 | 1159 | new=doc.new, |
1160 | 1160 | unk_coverage=doc.unk_coverage, |
1161 | - sequence=doc.sequence) | |
1161 | + sequence=1000000) | |
1162 | + seq = doc.sequence | |
1162 | 1163 | new_doc.keywords.add(*doc.keywords.all()) |
1163 | 1164 | subdocs = Document.objects.filter(parent=doc) |
1164 | 1165 | for subdoc in subdocs: |
... | ... | @@ -1178,6 +1179,9 @@ def change_doc_type(doc, target_type): |
1178 | 1179 | a.save() |
1179 | 1180 | |
1180 | 1181 | doc.delete() |
1182 | + new_doc.sequence = seq | |
1183 | + new_doc.save() | |
1184 | + | |
1181 | 1185 | return new_doc |
1182 | 1186 | |
1183 | 1187 | |
... | ... | @@ -1197,6 +1201,9 @@ class DocTypeView(UpdateView): |
1197 | 1201 | context = super().get_context_data(**kwargs) |
1198 | 1202 | context['title'] = 'Zmiana typu dokumentu' |
1199 | 1203 | context['submit_btn_text'] = 'Zmień' |
1204 | + if self.object.parent is None: | |
1205 | + messages.warning(self.request, 'Uwaga! Zmiana typu dokumentu głównego nie powoduje zmiany typów ' | |
1206 | + 'poddokumentów. Można je zmienić nastomiast manualnie.') | |
1200 | 1207 | messages.warning(self.request, 'Uwaga! Zmiana typu dokumentu może spowodować usunięcie danych typowych dla ' |
1201 | 1208 | 'tego typu.') |
1202 | 1209 | return context |
... | ... |