djangodocs.org

654 sections in Django 4.2 Search all versions →

ModelAdmin methods

Reference The Django admin site ModelAdmin objects

ModelAdmin.has_add_permission(request) : Should return True if adding an object is permitted, False otherwise. ModelAdmin.has_change_permission(request,obj=None) : Should return True if editing obj is permitted, False otherwise.

InlineModelAdmin options

Reference The Django admin site InlineModelAdmin objects

InlineModelAdmin.max_num : This controls the maximum number of forms to show in the inline. This doesn’t directly correlate to the number of objects, but can if the value is small enough.

AdminSite attributes

Reference The Django admin site AdminSite objects

AdminSite.login_form : Subclass of AuthenticationForm that will be used by the admin site login view. AdminSite.logout_template : Path to a custom template that will be used by the admin site logout view.

Reference GEOS API Geometry ObjectsGEOSGeometry

PreparedGeometry objects are optimized for the contains, intersects, covers, crosses, disjoint, overlaps, touches and within operations. Refer to the Prepared Geometries documentation for more information. GEOSGeometry.srs : Returns a SpatialReference object corresponding to the SRID of the geometry or None.

dumpdata

Reference django-admin and manage.py Available commands

--format FORMAT Specifies the serialization format of the output. Defaults to JSON. Supported formats are listed in Serialization formats. --indent INDENT Specifies the number of indentation spaces to use in the output.

Widget

Reference Widgets Base widget classes

classWidget(attrs=None) : This abstract class cannot be rendered, but provides the basic attribute attrs. You may also implement or override the render() method on custom widgets.

MultiWidget

Reference Widgets Base widget classes

classMultiWidget(widgets,attrs=None) : A widget that is composed of multiple widgets. MultiWidget works hand in hand with the MultiValueField.

DateField

Reference Model field reference Field types

If you want to be able to modify this field, set the following instead of auto_now_add=True: The default form widget for this field is a DateInput. The admin adds a JavaScript calendar, and a shortcut for “Today”.

FileField

Reference Model field reference Field types

See Managing files for details on how to provide this object. The default form widget for this field is a ClearableFileInput. Using a FileField or an ImageField (see below) in a model takes a few steps:

Field API reference

Reference Model field reference

classField : Field is an abstract class that represents a database table column. Django uses fields to create the database table (db_type()), to map Python types to database (get_prep_value()) and vice-versa (from_db_value()).

Field API reference

Reference Model field reference

When querying, [`get_db_prep_value()`](#django.db.models.Field.get_db_prep_value) and [`get_prep_value()`](#django.db.models.Field.get_prep_value) are used: `get_prep_value(value)` : `value` is the current value of the model’s attribute, and the method should return data in a format that has been prepared for use as a parameter in a query.

extra()

Reference QuerySet API reference QuerySet APIMethods that return new QuerySets

where / tables You can define explicit SQL WHERE clauses — perhaps to perform non-explicit joins — by using where. You can manually add tables to the SQL FROM clause by using tables.

Methods

Reference Request and response objects FileResponse objects

HttpRequest.get_host() : Returns the originating host of the request using information from the HTTP_X_FORWARDED_HOST (if USE_X_FORWARDED_HOST is enabled) and HTTP_HOST headers, in that order.

Methods

Reference Request and response objects FileResponse objects

HttpRequest.get_signed_cookie(key,default=RAISE_ERROR,salt='',max_age=None) : Returns a cookie value for a signed cookie, or raises a django.core.signing.BadSignature exception if the signature is no longer valid.

Topic guide Customizing authentication in Django Substituting a custom User model

Django’s built-in forms and views make certain assumptions about the user model that they are working with. The following forms are compatible with any subclass of AbstractBaseUser: AuthenticationForm: Uses the username field specified by USERNAME_FIELD.

Topic guide Using the Django authentication system Authentication in web requestsRedirecting unauthorized requests in class-based views

If your AUTH_USER_MODEL inherits from AbstractBaseUser or implements its own get_session_auth_hash() method, authenticated sessions will include the hash returned by this function. In the AbstractBaseUser case, this is an HMAC of the password field.

All authentication views

Topic guide Using the Django authentication system Authentication in web requestsAuthentication Views

logout_then_login(request,login_url=None) : Logs a user out on POST requests, then redirects to the login page. classPasswordChangeView : URL name: password_change classPasswordChangeDoneView : URL name: password_change_done classPasswordResetView : URL name: password_reset

Using class-based views

Topic guide Introduction to class-based views

… is worth noting that what your method returns is identical to what you return from a function-based view, namely some form of HttpResponse. This means that http shortcuts or TemplateResponse objects are valid to use inside a class-based view. While …