Ecosyste.ms: Awesome
An open API service indexing awesome lists of open source software.
https://github.com/swapno963/advance_orm
https://github.com/swapno963/advance_orm
Last synced: 26 days ago
JSON representation
- Host: GitHub
- URL: https://github.com/swapno963/advance_orm
- Owner: Swapno963
- Created: 2024-09-07T08:21:37.000Z (4 months ago)
- Default Branch: main
- Last Pushed: 2024-09-15T07:09:35.000Z (3 months ago)
- Last Synced: 2024-09-15T10:26:58.649Z (3 months ago)
- Size: 218 KB
- Stars: 0
- Watchers: 1
- Forks: 0
- Open Issues: 0
-
Metadata Files:
- Readme: README.md
Awesome Lists containing this project
README
# " Advance_ORM"
# Django Backend Concepts## 1. Models, Migrations, Admin Panel
- **Why Use It**: Models represent your database structure in Django, and migrations allow you to track changes to the database schema. The admin panel provides a quick way to manage data in your application without needing to build custom interfaces.
- **Real-World Use Case**: Building an e-commerce platform where you need to create and manage product models, categories, orders, and customers through an intuitive admin interface.## 2. Custom Validator
- **Why Use It**: Custom validators allow you to enforce specific rules for your model fields that are not covered by Django’s built-in validation. This helps maintain data integrity and meet business requirements.
- **Real-World Use Case**: Enforcing a password policy where the password must contain a special character, a number, and a minimum length.## 3. Updating and Deleting Queryset
- **Why Use It**: Updating or deleting querysets is crucial for managing data effectively in the database. This ensures you can modify or remove data based on dynamic conditions.
- **Real-World Use Case**: In a content management system, you might bulk update articles' status to “published” or delete old drafts that are no longer needed.## 4. Filter and Lookup
- **Why Use It**: Filters and lookups allow you to query the database for specific subsets of data, making it easier to retrieve the information you need.
- **Real-World Use Case**: Filtering blog posts by author, category, or date range, and using lookup expressions like `__icontains` to search for keywords in titles.## 5. Select Related and Prefetch Related
- **Why Use It**: These optimizations help reduce the number of database queries by loading related objects more efficiently. `select_related` is used for foreign key relationships, and `prefetch_related` is used for many-to-many or reverse foreign key relationships.
- **Real-World Use Case**: In a school management system, loading students along with their related classes and subjects in one efficient query instead of making multiple database hits.## 6. Many-to-Many Field
- **Why Use It**: Many-to-many fields represent relationships where multiple records of one model can be related to multiple records of another model.
- **Real-World Use Case**: In a social media application, users can belong to multiple groups, and each group can have multiple users.## 7. Aggregation and Annotation
- **Why Use It**: Aggregation functions like `Sum`, `Avg`, `Count`, and `Max` provide summaries of data, while `annotation` allows adding calculated fields to querysets.
- **Real-World Use Case**: Calculating the total sales, average rating, or the number of orders per customer in a sales application.## 8. F Expression
- **Why Use It**: `F` expressions allow you to perform operations on model fields directly in the database without loading the data into Python, making updates more efficient.
- **Real-World Use Case**: Incrementing a user’s score by 10 points in a game without fetching and updating the record manually.## 9. Q Objects
- **Why Use It**: `Q` objects allow you to create complex queries with `AND`, `OR`, and `NOT` conditions, which are useful for more advanced filtering.
- **Real-World Use Case**: Retrieving products that are either in stock or available for pre-order in an e-commerce platform using OR conditions.## 10. Coalesce Function and Handling Null Values
- **Why Use It**: `Coalesce` helps you replace `NULL` values with a default value in queries. This ensures that you don't run into unexpected `None` results in database queries.
- **Real-World Use Case**: Displaying a default price for products that haven’t had a price assigned yet in an inventory system.## 11. Case and When
- **Why Use It**: `Case` and `When` allow you to perform conditional logic within database queries, similar to if-else statements, but on the database side.
- **Real-World Use Case**: Applying discounts based on customer status (e.g., VIP, regular) when querying a list of orders in an online store.## 12. Summary of Real-World Use Cases:
- **Subquery**: Retrieve related data (like the latest comment for each post) in a single query.
- **OuterRef**: Reference the outer query’s fields (like the customer pk) within a subquery to find related data.
- **Exists**: Efficiently check if related data exists (like whether a job has any applications).