Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Update the unique bed name constraint to ignore deleted beds #2423

Closed
sainak opened this issue Sep 4, 2024 · 2 comments · Fixed by #2432
Closed

Update the unique bed name constraint to ignore deleted beds #2423

sainak opened this issue Sep 4, 2024 · 2 comments · Fixed by #2432
Assignees
Labels
bug Something isn't working

Comments

@sainak
Copy link
Member

sainak commented Sep 4, 2024

class Meta:
constraints = [
models.UniqueConstraint(
models.functions.Lower("name"),
"location",
name="unique_bed_name_per_location",
)
]
def __str__(self):
return self.name
def validate(self) -> None:
if (
Bed.objects.filter(location=self.location, name__iexact=self.name)
.exclude(pk=self.pk)
.exists()
):
raise ValidationError(
{"name": "Bed with same name already exists in location."}
)

@sainak sainak added the bug Something isn't working label Sep 4, 2024
@sainak sainak self-assigned this Sep 4, 2024
@DraKen0009
Copy link
Contributor

@sainak can I pick this issue ?

Copy link

sentry-io bot commented Sep 7, 2024

Sentry Issue: CARE-6TJ

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bug Something isn't working
Projects
Status: Done
Development

Successfully merging a pull request may close this issue.

2 participants