Smart enough to know if your model exists
1 file changed, +2 -1
+2-1rango/backend/api/management/commands/createapi.py
| @@ -26,7 +26,8 @@ class Command(BaseCommand): | ||
| 26 | 26 | } |
| 27 | 27 | # If the api model does not exist raise a CommandError |
| 28 | 28 | try: |
| 29 | - __import__(f'{root_dir}.models.{model_name}') | |
| 29 | + # Test if the model exists | |
| 30 | + getattr(__import__(root_dir).models, model_name) | |
| 30 | 31 | except: |
| 31 | 32 | raise CommandError(f"Model {model_name} does not exist") |
| 32 | 33 | # If the root directory does not exist raise a CommandError |