Loading...
Loading...
Master Django model creation with this comprehensive AI prompt featuring best practices for data planning, relationships, performance optimization, and scalability. Get tailored strategies to build efficient, robust models that supercharge your backend development.
Act as a senior Django developer with deep expertise in database design and optimization. I need help creating and optimizing Django models for my project. Here's the context: [describe your app's purpose, key entities, attributes, relationships, and any performance concerns]. Guide me step by step through the best approaches. First, Planning Your Data Structure: Start by mapping out all entities, their attributes, and how they interconnect. Think about the real-world objects your app handles and sketch relationships like one-to-many or many-to-many to ensure your models reflect the business logic accurately. Next, Naming and Field Selection: Use descriptive, intuitive names for fields and models, following Python and Django conventions (e.g., snake_case). Pick the right field types—CharField for text, IntegerField for numbers, DateTimeField for timestamps, BooleanField for flags—and add validators, defaults, or choices where they make sense to enforce data quality. Handling Relationships: Define ForeignKey for one-to-many, OneToOneField for unique links, and ManyToManyField for flexible associations. Always consider the direction of relationships, on_delete options, and whether to use related_name for cleaner queries. Normalization and Inheritance: Aim for normalization to eliminate redundancy, but know when to denormalize for speed. Leverage abstract base models for shared fields and behaviors across models, and concrete inheritance for extending base functionality without repeating code. Custom Logic and Managers: Add custom methods to models for business rules, like calculated properties or save overrides. Create custom managers and QuerySets for reusable query patterns, keeping your views clean. Performance Optimization: Add indexes via db_index or Meta indexes on frequently queried fields. Use select_related for forward ForeignKeys and prefetch_related for reverse or ManyToMany to cut down on N+1 queries. Suggest values() or only() for lightweight selects. Advanced Tips: Use Django's Meta options for ordering, unique_together, constraints, and permissions. Integrate migrations properly for schema evolution. Recommend tools like Django Debug Toolbar for profiling. Finally, provide sample model code based on my description, plus tests and documentation snippets. Output in a structured format: 1) Recommended models with code. 2) Explanation of choices. 3) Optimization recommendations. 4) Potential pitfalls and how to avoid them.
Structured web research using ChatGPT's browsing capability. Systematic source evaluation, fact-checking, and synthesis with proper citations.
Design production-ready ChatGPT API integrations. Covers authentication, streaming, function calling, structured outputs, and cost optimization with the latest OpenAI SDK.
Step-by-step data analysis pipeline using ChatGPT's Code Interpreter. Upload CSV/Excel files for cleaning, visualization, statistical analysis, and insights.
Optimize ChatGPT's memory feature for persistent context. Teaches how to structure memories, manage what's stored, and leverage personalization effectively.
Generate precise, creative DALL-E 3 prompts. Handles style specifications, aspect ratios, composition rules, and iterative refinement for stunning AI-generated images.
Leverage ChatGPT Canvas mode for iterative document editing, code review, and collaborative writing with inline suggestions and tracked changes.