Skip to content

jkingportfolio/django-cheatsheet

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

3 Commits
 
 

Repository files navigation

Django Cheatsheet My Skills

Welcome to the Django Cheatsheet repository! This repository serves as a comprehensive reference guide for Django, a high-level Python web framework. Whether you're a beginner learning Django or an experienced developer seeking a quick reference, this cheatsheet is designed to help you build powerful and scalable web applications with ease.

The cheatsheet covers various aspects of Django, including project setup, models, views, templates, forms, authentication, database queries, URL routing, static files, testing, and deployment. Each section provides concise explanations, code snippets, and best practices to assist you in mastering Django's key concepts.

Feel free to explore this cheatsheet to enhance your Django skills, streamline your development process, and create robust web applications. The cheatsheet is written in Markdown format, making it easy to view, copy, and paste into your own projects.

If you have any suggestions or would like to contribute to this cheatsheet, please feel free to open an issue or submit a pull request. Let's collaborate and make this cheatsheet a valuable resource for the Django community!

Happy Django coding!

Table of Contents

  1. Introduction to Django
  2. Django Installation
  3. Django Project Structure
  4. Creating a Django Project
  5. Django Apps
  6. Models and Databases
  7. Creating Models
  8. Defining Model Fields
  9. Migrations
  10. Django Admin
  11. Registering Models in Admin
  12. URL Patterns and Routing
  13. Django Views
  14. Function-Based Views
  15. Class-Based Views
  16. Templates and Template Language
  17. Template Variables and Filters
  18. Template Inheritance
  19. Static Files and Media Files
  20. Django Forms
  21. Form Validation
  22. Working with Form Data
  23. Model Forms
  24. Form Widgets
  25. File Uploads
  26. Authentication and Authorization
  27. User Authentication with Django's User Model
  28. Custom User Model
  29. Permissions and Authorization
  30. Django Middleware
  31. Working with Sessions
  32. Caching with Django
  33. Django Signals
  34. Django Template Tags and Filters
  35. Custom Template Tags and Filters
  36. Internationalization and Localization
  37. Django Testing
  38. Unit Testing with Django
  39. Integration Testing with Django
  40. Test Fixtures
  41. Working with QuerySets
  42. Filtering QuerySets
  43. QuerySet Methods
  44. Aggregation and Annotation
  45. Relationships and Foreign Keys
  46. Many-to-Many Relationships
  47. One-to-One Relationships
  48. Django ORM
  49. Querying the Database
  50. Creating and Updating Objects
  51. Deleting Objects
  52. Common Datetime Formats in Django
  53. Django REST Framework Basics
  54. Serializers in Django REST Framework
  55. Authentication and Permissions in Django REST Framework
  56. API Views and ViewSets
  57. File Uploads in Django REST Framework
  58. Pagination in Django REST Framework
  59. Versioning in Django REST Framework
  60. Django Deployment Best Practices
  61. Troubleshooting Common Django Issues

Common Datetime Formats in Django

When working with datetime fields in a Django project, you have the flexibility to customize the display format of dates and times. Django provides various format codes that you can use to represent datetime values according to your preferences. Below is a list of common datetime formats that you can use in your Django project.

Date Formats %Y - Year with century (e.g., 2023)
%y - Year without century (e.g., 23)
%m - Month as a zero-padded decimal number (01 to 12)
%b - Abbreviated month name (Jan, Feb, etc.)
%B - Full month name (January, February, etc.)
%d - Day of the month as a zero-padded decimal number (01 to 31)

Example: "2023-04-08"

DATE_FORMAT = "%Y-%m-%d"

Time Formats %H - Hour (24-hour clock) as a zero-padded decimal number (00 to 23)
%I - Hour (12-hour clock) as a zero-padded decimal number (01 to 12)
%M - Minute as a zero-padded decimal number (00 to 59)
%S - Second as a zero-padded decimal number (00 to 59)
%p - AM or PM

Example: "15:30:00"

TIME_FORMAT = "%H:%M:%S"

Datetime Formats
%Y-%m-%d %H:%M:%S - Datetime with year, month, day, hour, minute, and second (e.g., 2023-04-08 15:30:00)
%Y-%m-%d %I:%M:%S %p - Datetime with year, month, day, 12-hour clock, minute, second, and AM/PM (e.g., 2023-04-08 03:30:00 PM)

Example: "2023-04-08 15:30:00"

DATETIME_FORMAT = "%Y-%m-%d %H:%M:%S"

Custom Formats You can also create custom datetime formats by combining the above format codes and any additional characters you need.

Usage To apply a datetime format, update the respective format setting in your project's settings.py file. Remember to use these formats within Django's context, such as templates and serializers, to ensure consistent presentation of datetime values.

Feel free to choose the formats that best suit your project's requirements and design.

About

Cheat / Help sheet repo for Django

Resources

Stars

Watchers

Forks

Releases

No releases published

Packages

No packages published