November 2015
Beginner to intermediate
840 pages
26h 30m
English
Tag Model slug FieldOur slug field clean method, clean_slug(), must do two things:
1. Ensure that slug is lowercase (to prevent alphabetization and conflicts).
2. Ensure slug is not create (to prevent URL path collision).
Item 1 is straightforward, as we saw in the clean_name() method. However, in the event that item 2 fails, there is no clear and simple course of action to rectify the problem. Following Python’s explicit nature, we should therefore raise an error. As such, we must first import the ValidationError exception, which Django expects developers to raise in the event a value cannot be validated. In /organizer/forms.py, we add the import from django.core.exceptions import ValidationError. We can ...
Read now
Unlock full access