Skip to content

Commit d0a5497

Browse files
Update docs for on_delete requirement in Filer fields for Django 5.1
Update documentation to reflect the requirement of the `on_delete` parameter for `FilerFileField` and `FilerImageField`, ensuring compatibility with Django 5.1. Documentation: - Update documentation to indicate that the `on_delete` parameter is required when using `FilerFileField` and `FilerImageField`. - Add example code in the documentation showing proper field definition with the `on_delete` parameter. - Review and update other field examples in the documentation to ensure they include required parameters. Resolves #1506
1 parent 93ffea5 commit d0a5497

File tree

1 file changed

+18
-7
lines changed

1 file changed

+18
-7
lines changed

docs/usage.rst

Lines changed: 18 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -42,9 +42,11 @@ Simple example ``models.py``::
4242
class Company(models.Model):
4343
name = models.CharField(max_length=255)
4444
logo = FilerImageField(null=True, blank=True,
45-
related_name="logo_company")
45+
related_name="logo_company",
46+
on_delete=models.SET_NULL)
4647
disclaimer = FilerFileField(null=True, blank=True,
47-
related_name="disclaimer_company")
48+
related_name="disclaimer_company",
49+
on_delete=models.SET_NULL)
4850

4951
multiple file fields on the same model::
5052

@@ -53,12 +55,21 @@ multiple file fields on the same model::
5355

5456
class Book(models.Model):
5557
title = models.CharField(max_length=255)
56-
cover = FilerImageField(related_name="book_covers")
57-
back = FilerImageField(related_name="book_backs")
58+
cover = FilerImageField(related_name="book_covers",
59+
on_delete=models.CASCADE)
60+
back = FilerImageField(related_name="book_backs",
61+
on_delete=models.CASCADE)
5862

59-
As with `django.db.models.ForeignKey`_ in general, you have to define a
60-
non-clashing ``related_name`` if there are multiple ``ForeignKey`` s to the
61-
same model.
63+
As with `django.db.models.ForeignKey`_ in general:
64+
65+
* You must specify an ``on_delete`` parameter to define what happens when the referenced file is deleted
66+
* You have to define a non-clashing ``related_name`` if there are multiple ``ForeignKey`` s to the same model
67+
68+
Common ``on_delete`` options:
69+
70+
* ``models.CASCADE`` - Delete the model containing the FilerFileField when the referenced file is deleted
71+
* ``models.SET_NULL`` - Set the reference to NULL when the file is deleted (requires ``null=True``)
72+
* ``models.PROTECT`` - Prevent deletion of the referenced file
6273

6374
templates
6475
.........

0 commit comments

Comments
 (0)