-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
[#11] product needs at least 1 eigenaar
- Loading branch information
Showing
7 changed files
with
117 additions
and
57 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,10 +1,26 @@ | ||
from django.contrib import admin | ||
from django.core.exceptions import ValidationError | ||
from django.utils.translation import gettext_lazy as _ | ||
|
||
from open_producten.logging.admin_tools import AuditLogInlineformset | ||
from open_producten.producten.models import Eigenaar | ||
|
||
|
||
class EigenaarInlineFormSet(AuditLogInlineformset): | ||
|
||
def clean(self): | ||
"""Check that at least one optie has been added.""" | ||
super().clean() | ||
if any(self.errors): | ||
return | ||
if not any( | ||
cleaned_data and not cleaned_data.get("DELETE", False) | ||
for cleaned_data in self.cleaned_data | ||
): | ||
raise ValidationError(_("Er is minimaal één optie vereist.")) | ||
|
||
|
||
class EigenaarInline(admin.TabularInline): | ||
formset = AuditLogInlineformset | ||
formset = EigenaarInlineFormSet | ||
model = Eigenaar | ||
extra = 1 |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.