class FileUpload(models.Model):
owner = models.CharField(max_length=200,blank=False, null=False)
record = models.FileField(upload_to=path_and_rename)
def save(self, force_insert=False, force_update=False, *args, **kwargs):
if not bool(self.record):
raise ValidationError("Record is required")
super(FileUpload, self).save(force_insert, force_update, *args, **kwargs)
Best regards,
Cyril
Le vendredi 14 août 2020 à 20:34:31 UTC+1, cyril....@gmail.com a écrit :
Hi,Is it possible to mark a FileField in my model as requiredMy model looks like :class FileUpload(models.Model):owner = models.CharField(max_length=200,blank=False, null=False)record = models.FileField(upload_to=path_and_rename,blank=False, null=False)1st statement :According to what i have read the blank and null parameter are not necessaryand only the parameter "upload_to" and "storage" are availables2nd statement :Secondly, it seems that the field validation are done at the form level or serializer level.I would like to know if these 2 statements are true?when I use python manage.py shell and make a test of creating a FileUpload object and save it, i dont get any error saying the that filefield is required :## steps :test = FileUpload(owner="test")test.save()## expected :Error : filefield "record" is required!## actual behavior :save the object without errorIs it possible to put the filefield as required at the model level?orDo i have to make the validation of the field before/at an upper level?Thank youCyril
You received this message because you are subscribed to the Google Groups "Django users" group.
To unsubscribe from this group and stop receiving emails from it, send an email to django-users+unsubscribe@googlegroups.com.
To view this discussion on the web visit https://groups.google.com/d/msgid/django-users/8756d5bf-2619-4e72-809b-e107e6736c68n%40googlegroups.com.
No comments:
Post a Comment