WIP: Lot groups search/filtering and lot groups panel ui changes #61
22
lot/migrations/0008_lot_unique_institution_and_name.py
Normal file
22
lot/migrations/0008_lot_unique_institution_and_name.py
Normal file
|
@ -0,0 +1,22 @@
|
||||||
|
# Generated by Django 5.0.6 on 2025-02-21 20:58
|
||||||
|
|
||||||
|
from django.conf import settings
|
||||||
|
from django.db import migrations, models
|
||||||
|
|
||||||
|
|
||||||
|
class Migration(migrations.Migration):
|
||||||
|
|
||||||
|
dependencies = [
|
||||||
|
("lot", "0007_lottag_inbox"),
|
||||||
|
("user", "0002_institution_algorithm"),
|
||||||
|
migrations.swappable_dependency(settings.AUTH_USER_MODEL),
|
||||||
|
]
|
||||||
|
|
||||||
|
operations = [
|
||||||
|
migrations.AddConstraint(
|
||||||
|
model_name="lot",
|
||||||
|
constraint=models.UniqueConstraint(
|
||||||
|
fields=("owner", "name"), name="unique_institution_and_name"
|
||||||
|
),
|
||||||
|
),
|
||||||
|
]
|
13
lot/views.py
13
lot/views.py
|
@ -39,9 +39,16 @@ class NewLotView(DashboardView, CreateView):
|
||||||
return form
|
return form
|
||||||
|
|
||||||
def form_valid(self, form):
|
def form_valid(self, form):
|
||||||
form.instance.owner = self.request.user.institution
|
try:
|
||||||
form.instance.user = self.request.user
|
form.instance.owner = self.request.user.institution
|
||||||
response = super().form_valid(form)
|
form.instance.user = self.request.user
|
||||||
|
response = super().form_valid(form)
|
||||||
|
return response
|
||||||
|
|
||||||
|
except IntegrityError:
|
||||||
|
messages.error(self.request, _("Lot name is already defined."))
|
||||||
|
return self.form_invalid(form)
|
||||||
|
|
||||||
return response
|
return response
|
||||||
|
|
||||||
|
|
||||||
|
|
Loading…
Reference in a new issue