Add source_site_id to ActiveSite model and implement unique constraint. Update serializers and views for site registration and claiming. Enhance tests for site registration and claiming functionality.
This commit is contained in:
1 parent
521f36d22d
commit
61f954a3bd
12 files changed
+684
-172
No files matched your search
@@ -15,6 +15,13 @@ class ActiveSite(models.Model):
|
||||
active_site_id = models.BigAutoField(primary_key=True)
|
||||
code = models.SlugField(max_length=64, unique=True, help_text="Stable id, e.g. sukawarna")
|
||||
name = models.CharField(max_length=120)
|
||||
source_site_id = models.SlugField(
|
||||
max_length=64,
|
||||
blank=True,
|
||||
default="",
|
||||
db_index=True,
|
||||
help_text="Farm-location Site.site_id (slug) from the registering dashboard",
|
||||
)
|
||||
api_base_url = models.URLField(
|
||||
max_length=255,
|
||||
blank=True,
|
||||
@@ -44,6 +51,13 @@ class ActiveSite(models.Model):
|
||||
class Meta:
|
||||
db_table = "active_sites"
|
||||
ordering = ["name"]
|
||||
constraints = [
|
||||
models.UniqueConstraint(
|
||||
fields=["source_site_id"],
|
||||
condition=~models.Q(source_site_id=""),
|
||||
name="uniq_active_site_source_site_id",
|
||||
),
|
||||
]
|
||||
|
||||
def __str__(self) -> str:
|
||||
return f"{self.name} ({self.code})"
|
||||
Reference in new issue
Block a user