Skip to content

Commit

Permalink
Update docs for on_delete requirement in Filer fields for Django 5.1
Browse files Browse the repository at this point in the history
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
  • Loading branch information
sourcery-ai[bot] committed Nov 19, 2024
1 parent 93ffea5 commit d0a5497
Showing 1 changed file with 18 additions and 7 deletions.
25 changes: 18 additions & 7 deletions docs/usage.rst
Original file line number Diff line number Diff line change
Expand Up @@ -42,9 +42,11 @@ Simple example ``models.py``::
class Company(models.Model):
name = models.CharField(max_length=255)
logo = FilerImageField(null=True, blank=True,
related_name="logo_company")
related_name="logo_company",
on_delete=models.SET_NULL)
disclaimer = FilerFileField(null=True, blank=True,
related_name="disclaimer_company")
related_name="disclaimer_company",
on_delete=models.SET_NULL)

multiple file fields on the same model::

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

class Book(models.Model):
title = models.CharField(max_length=255)
cover = FilerImageField(related_name="book_covers")
back = FilerImageField(related_name="book_backs")
cover = FilerImageField(related_name="book_covers",
on_delete=models.CASCADE)
back = FilerImageField(related_name="book_backs",
on_delete=models.CASCADE)

As with `django.db.models.ForeignKey`_ in general, you have to define a
non-clashing ``related_name`` if there are multiple ``ForeignKey`` s to the
same model.
As with `django.db.models.ForeignKey`_ in general:

* You must specify an ``on_delete`` parameter to define what happens when the referenced file is deleted
* You have to define a non-clashing ``related_name`` if there are multiple ``ForeignKey`` s to the same model

Common ``on_delete`` options:

* ``models.CASCADE`` - Delete the model containing the FilerFileField when the referenced file is deleted
* ``models.SET_NULL`` - Set the reference to NULL when the file is deleted (requires ``null=True``)
* ``models.PROTECT`` - Prevent deletion of the referenced file

templates
.........
Expand Down

0 comments on commit d0a5497

Please sign in to comment.