def save(self, *args, **kwargs): type = self.feed_type subscriber = self.subscriber similar = self.__class__.objects\ .filter(feed_type=type, subscriber=subscriber)\ .exclude(pk=self.id) if similar.exists(): raise IntegrityError('email feed setting already exists') super(EmailFeedSetting, self).save(*args, **kwargs)
def populate_words(request): if request.method == 'POST': language = Language.objects.get(name=request.POST['language']) file = request.FILES['file'] words = [] for line in file: if line == "\n" or line == " \n": continue word = Word(word=line, language=language) words.append(word.word) try: word.save() except: IntegrityError() context = {"words": words} return render(request, 'trainer/upload_success.html', context) else: form = UploadFileForm() return render(request, 'trainer/populate.html', {'form': form}) return render(request, 'trainer/populate.html')