How to use validate_unique method in autotest

Best Python code snippet using autotest_python

forms.py

Source:forms.py Github

copy

Full Screen

...14 }15 def __init__(self, festival, *args, **kwargs):16 self.festival = festival17 super().__init__(*args, **kwargs)18 def validate_unique(self):19 exclude = self._get_validation_exclusions()20 exclude.remove('festival')21 self.instance.festival = self.festival22 try:23 self.instance.validate_unique(exclude)24 except ValidationError:25 self._update_errors(ValidationError({'name': 'A page with that name already exists'}))26class AdminPageImageForm(forms.ModelForm):27 class Meta:28 model = PageImage29 fields = [30 'name',31 'image',32 ]33 def __init__(self, page, *args, **kwargs):34 self.page = page35 super().__init__(*args, **kwargs)36 def validate_unique(self):37 exclude = self._get_validation_exclusions()38 exclude.remove('page')39 self.instance.page = self.page40 try:41 self.instance.validate_unique(exclude=exclude)42 except ValidationError:43 self._update_errors(ValidationError({'name': 'An image with that name already exists'}))44class AdminNavigatorForm(forms.ModelForm):45 class Meta:46 model = Navigator47 fields = [48 'seqno', 'label',49 'type', 'url', 'page',50 ]51 def __init__(self, festival, *args, **kwargs):52 self.festival = festival53 super().__init__(*args, **kwargs)54 self.fields['page'].queryset = Page.objects.filter(festival=festival)55 # Same check - different error message (to avoid mention of festival)56 def validate_unique(self):57 exclude = self._get_validation_exclusions()58 exclude.remove('festival')59 self.instance.festival = self.festival60 try:61 self.instance.validate_unique(exclude=exclude)62 except ValidationError:63 self._update_errors(ValidationError({'name': 'A navigator with that name already exists'}))64class AdminImageForm(forms.ModelForm):65 class Meta:66 model = Image67 fields = [68 'name',69 'image',70 ]71 def __init__(self, festival, *args, **kwargs):72 self.festival = festival73 super().__init__(*args, **kwargs)74 # Same check - different error message (to avoid mention of festival)75 def validate_unique(self):76 exclude = self._get_validation_exclusions()77 exclude.remove('festival')78 self.instance.festival = self.festival79 try:80 self.instance.validate_unique(exclude=exclude)81 except ValidationError:82 self._update_errors(ValidationError({'name': 'A image with that name already exists'}))83class AdminDocumentForm(forms.ModelForm):84 class Meta:85 model = Document86 fields = [87 'name',88 'file', 'filename',89 ]90 def __init__(self, festival, *args, **kwargs):91 self.festival = festival92 super().__init__(*args, **kwargs)93 # Same check - different error message (to avoid mention of festival)94 def validate_unique(self):95 exclude = self._get_validation_exclusions()96 exclude.remove('festival')97 self.instance.festival = self.festival98 try:99 self.instance.validate_unique(exclude=exclude)100 except ValidationError:101 self._update_errors(ValidationError({'name': 'A document with that name already exists'}))102class AdminResourceForm(forms.ModelForm):103 class Meta:104 model = Resource105 fields = [106 'name',107 'type',108 'body', 'body_test',109 ]110 def __init__(self, festival, *args, **kwargs):111 self.festival = festival112 super().__init__(*args, **kwargs)113 def validate_unique(self):114 exclude = self._get_validation_exclusions()115 exclude.remove('festival')116 self.instance.festival = self.festival117 try:118 self.instance.validate_unique(exclude)119 except ValidationError:...

Full Screen

Full Screen

models.py

Source:models.py Github

copy

Full Screen

1from typing import List2from django.db import models3# Create your models here.4from django.db import models5class Segment(models.Model):6 created_at = models.DateTimeField('date created', auto_now_add=True, db_index=True)7 experiment_name = models.TextField('name of experiment')8 def full_clean(self, exclude=None, validate_unique=True):9 super(Segment, self).full_clean(exclude=exclude, validate_unique=validate_unique)10class Feature(models.Model):11 created_at = models.DateTimeField('date created', auto_now_add=True, db_index=True)12 segment = models.ForeignKey(Segment, related_name='features', on_delete=models.CASCADE)13 name = models.TextField('feature name', default="")14 value = models.FloatField('feature value', default=0.0)15 def full_clean(self, exclude=None, validate_unique=True):16 super(Feature, self).full_clean(exclude=exclude, validate_unique=validate_unique)17class Image(models.Model):18 created_at = models.DateTimeField('date created', auto_now_add=True, db_index=True)19 prediction = models.TextField(max_length=100, default='Not available')20 ground_truth = models.TextField(max_length=100, default='No available')21 segment = models.ForeignKey(Segment, related_name='images', on_delete=models.CASCADE)22 image = models.TextField(max_length=240)23 def full_clean(self, exclude=None, validate_unique=True):24 super(Image, self).full_clean(exclude=exclude, validate_unique=validate_unique)25class Comparison(models.Model):26 created_at = models.DateTimeField('date created', auto_now_add=True, db_index=True)27 updated_at = models.DateTimeField(auto_now=True, db_index=True)28 rated = models.BooleanField(default=False)29 winner = models.IntegerField(default=99999999)30 experiment_name = models.TextField('name of experiment')31 segments = models.ManyToManyField(Segment)32def get_features_to_array_from_segment(segment:Segment, order:List[Feature])->List[float]:33 res = []34 for feature in order:35 for sfeature in list(segment.features.all()):36 if feature.name == sfeature.name:37 res.append(sfeature.value)38 #if sfeature.name == 'val_accuracy':39 # res = [sfeature.value]...

Full Screen

Full Screen

Automation Testing Tutorials

Learn to execute automation testing from scratch with LambdaTest Learning Hub. Right from setting up the prerequisites to run your first automation test, to following best practices and diving deeper into advanced test scenarios. LambdaTest Learning Hubs compile a list of step-by-step guides to help you be proficient with different test automation frameworks i.e. Selenium, Cypress, TestNG etc.

LambdaTest Learning Hubs:

YouTube

You could also refer to video tutorials over LambdaTest YouTube channel to get step by step demonstration from industry experts.

Run autotest automation tests on LambdaTest cloud grid

Perform automation testing on 3000+ real desktop and mobile devices online.

Try LambdaTest Now !!

Get 100 minutes of automation test minutes FREE!!

Next-Gen App & Browser Testing Cloud

Was this article helpful?

Helpful

NotHelpful