Original code copyright (C) 2009-2022 Rudolf Cardinal (

This file is part of cardinal_pythonlib.

Licensed under the Apache License, Version 2.0 (the “License”); you may not use this file except in compliance with the License. You may obtain a copy of the License at

Unless required by applicable law or agreed to in writing, software distributed under the License is distributed on an “AS IS” BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the License for the specific language governing permissions and limitations under the License.

Django field class storing a file (by reference to a disk file, as for “django.db.models.FileField”) but also implementing limits on the maximum upload size.

class cardinal_pythonlib.django.fields.restrictedcontentfile.ContentTypeRestrictedFileField(*args, **kwargs)[source]

Same as FileField, but you can specify:

  • content_types - list containing allowed content_types. Example: ['application/pdf', 'image/jpeg']

  • max_upload_size - a number indicating the maximum file size allowed for upload.

    2.5MB - 2621440
    5MB - 5242880
    10MB - 10485760
    20MB - 20971520
    50MB - 5242880
    100MB - 104857600
    250MB - 214958080
    500MB - 429916160


clean(*args, **kwargs) Any[source]

Convert the value’s type and run validation. Validation errors from to_python() and validate() are propagated. Return the correct value if no error is raised.