Skip to content

Instantly share code, notes, and snippets.

@lozadaOmr
Last active June 17, 2017 11:04
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save lozadaOmr/b17f87ea0f2e5a24b1f73c31c5136dac to your computer and use it in GitHub Desktop.
Save lozadaOmr/b17f87ea0f2e5a24b1f73c31c5136dac to your computer and use it in GitHub Desktop.
# 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