Skip to content

Commit

Permalink
Enable blank values for safe-app provider (#115)
Browse files Browse the repository at this point in the history
- SafeApp.provider can now be blank
- The blank field is used for validation when creating an instance for the model whereas null is only used for the database (see: https://docs.djangoproject.com/en/dev/ref/models/fields/#blank)
  • Loading branch information
fmrsabino authored Jun 18, 2021
1 parent 07c7066 commit fb8819f
Show file tree
Hide file tree
Showing 3 changed files with 34 additions and 1 deletion.
24 changes: 24 additions & 0 deletions src/safe_apps/migrations/0003_alter_safeapp_provider.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,24 @@
# Generated by Django 3.2.4 on 2021-06-18 12:28

import django.db.models.deletion
from django.db import migrations, models


class Migration(migrations.Migration):

dependencies = [
("safe_apps", "0002_rename_networks_safeapp_chain_ids"),
]

operations = [
migrations.AlterField(
model_name="safeapp",
name="provider",
field=models.ForeignKey(
blank=True,
null=True,
on_delete=django.db.models.deletion.SET_NULL,
to="safe_apps.provider",
),
),
]
4 changes: 3 additions & 1 deletion src/safe_apps/models.py
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,9 @@ class SafeApp(models.Model):
icon_url = models.URLField()
description = models.CharField(max_length=200)
chain_ids = ArrayField(models.IntegerField())
provider = models.ForeignKey(Provider, null=True, on_delete=models.SET_NULL)
provider = models.ForeignKey(
Provider, null=True, blank=True, on_delete=models.SET_NULL
)

def __str__(self):
return f"{self.name} | {self.url} | chain_ids={self.chain_ids}"
7 changes: 7 additions & 0 deletions src/safe_apps/tests/test_models.py
Original file line number Diff line number Diff line change
Expand Up @@ -16,3 +16,10 @@ def test_str_method_outputs_name_url_chain_id(self):
str(safe_app),
f"{safe_app.name} | {safe_app.url} | chain_ids={safe_app.chain_ids}",
)

@staticmethod
def test_empty_provider_validation():
safe_app = SafeAppFactory.create(provider=None)

# Run validations including blank checks
safe_app.full_clean()

0 comments on commit fb8819f

Please sign in to comment.