-
-
Save lozadaOmr/b17f87ea0f2e5a24b1f73c31c5136dac to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
# forms.py | |
class Form(ModelForm): | |
class Meta: | |
model = Repository | |
fields = ['repository'] | |
def clean_repository(self): | |
if self.instance.check_repository_exists(): | |
raise ValidationError('Repository exists') | |
return self.cleaned_data | |
# models.py | |
class Repository(models.Model): | |
repository = models.CharField(max_length=100) | |
def get_dir_name(self): | |
return os.path.join(settings.REPOSITORY_DIR, self.repository) | |
def check_repository_exists(self): | |
return os.path.exists(self.get_dir_name()) | |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment