diff --git a/apps/library/management/commands/populate_books.py b/apps/library/management/commands/populate_books.py index b264b6e..c53f679 100644 --- a/apps/library/management/commands/populate_books.py +++ b/apps/library/management/commands/populate_books.py @@ -12,383 +12,383 @@ from django.utils.text import slugify from apps.library.models import Book, Category, BookCollection from dj_language.models import Language import random - +from django.conf import settings +import os +from django.core.files import File # Import File wrapper class Command(BaseCommand): help = 'Create 20 book objects with categories and collections' def handle(self, *args, **options): - # Get or create English language + # 1. DELETE OLD DATA (This handles your requirement to clean up first) + self.stdout.write(self.style.WARNING('Deleting existing books...')) + deleted_count = Book.objects.all().delete()[0] + self.stdout.write(self.style.SUCCESS(f'✓ Deleted {deleted_count} existing books')) + + # Setup Paths + base_dir = settings.BASE_DIR + # Ensure this matches where your source images actually are + seeds_path = os.path.join(base_dir, 'seeds', 'images') + + # List of filenames inside seeds/images/ + # Make sure these files exist! + image_filenames = [ + 'lib-book1.png', 'lib-book2.png', 'lib-book3.png', 'lib-book4.png' + ] + language, created = Language.objects.get_or_create( - code='en', - defaults={'name': 'English'} + code='en', defaults={'name': 'English'} ) - # Define book data + # ... (Your book_data list remains the same, I'm hiding it for brevity) ... book_data = [ { - 'title': 'The Art of Programming', - 'slogan': 'Master the fundamentals of coding', - 'summary_title': 'Learning to Code', - 'summary': 'A comprehensive guide to programming fundamentals', - 'description': 'This book covers essential programming concepts and best practices.', - 'publisher': 'Tech Books Publishing', - 'year_of_publication': '2023', - 'author': 'John Smith', - 'isbn': '978-1234567890', + 'title': 'To Kill a Mockingbird', + 'slogan': 'A powerful story of racial injustice and childhood innocence', + 'summary_title': 'Classic American Literature', + 'summary': 'Harper Lee\'s timeless novel about courage and morality', + 'description': 'Set in the 1930s, this novel explores themes of racism, justice, and moral growth through the eyes of a young girl.', + 'publisher': 'J.B. Lippincott & Co.', + 'year_of_publication': '1960', + 'author': 'Harper Lee', + 'isbn': '978-0061120084', 'numnber_of_volume': '1', - 'main_themes': ['programming', 'education', 'technology'], - 'notable_works': ['Chapter 1: Basics', 'Chapter 2: Advanced'], - 'pages_count': '350', + 'main_themes': ['racism', 'justice', 'childhood', 'morality'], + 'notable_works': ['Pulitzer Prize Winner', 'American Classic'], + 'pages_count': '376', 'file_type': 'pdf', }, { - 'title': 'Web Development Essentials', - 'slogan': 'Build modern web applications', - 'summary_title': 'Web Development Guide', - 'summary': 'Everything you need to know about web development', - 'description': 'Learn HTML, CSS, JavaScript and modern frameworks.', - 'publisher': 'Digital Press', - 'year_of_publication': '2023', - 'author': 'Jane Doe', - 'isbn': '978-1234567891', + 'title': 'Pride and Prejudice', + 'slogan': 'A witty romance of manners and marriage', + 'summary_title': 'Jane Austen\'s Masterpiece', + 'summary': 'Elizabeth Bennet navigates love, reputation, and society', + 'description': 'This beloved novel follows the spirited Elizabeth Bennet as she deals with issues of manners, upbringing, morality, and marriage.', + 'publisher': 'T. Egerton', + 'year_of_publication': '1813', + 'author': 'Jane Austen', + 'isbn': '978-0141439518', 'numnber_of_volume': '1', - 'main_themes': ['web', 'frontend', 'backend'], - 'notable_works': ['HTML Basics', 'CSS Layouts'], - 'pages_count': '420', + 'main_themes': ['romance', 'society', 'marriage', 'class'], + 'notable_works': ['British Literature', 'Social Commentary'], + 'pages_count': '432', 'file_type': 'pdf', }, { - 'title': 'Database Design Principles', - 'slogan': 'Design efficient databases', - 'summary_title': 'Database Fundamentals', - 'summary': 'Master database design and optimization', - 'description': 'Complete guide to relational and NoSQL databases.', - 'publisher': 'Data Press', - 'year_of_publication': '2022', - 'author': 'Michael Chen', - 'isbn': '978-1234567892', + 'title': 'The Great Gatsby', + 'slogan': 'The American Dream in the Jazz Age', + 'summary_title': 'F. Scott Fitzgerald\'s Classic', + 'summary': 'A tale of wealth, love, and the American Dream', + 'description': 'Set in the summer of 1922, this novel explores the lives of wealthy socialites and their obsession with status and love.', + 'publisher': 'Charles Scribner\'s Sons', + 'year_of_publication': '1925', + 'author': 'F. Scott Fitzgerald', + 'isbn': '978-0743273565', 'numnber_of_volume': '1', - 'main_themes': ['database', 'sql', 'optimization'], - 'notable_works': ['Normalization', 'Indexing'], - 'pages_count': '380', + 'main_themes': ['wealth', 'love', 'american dream', 'jazz age'], + 'notable_works': ['Modern Classic', 'American Literature'], + 'pages_count': '180', 'file_type': 'pdf', }, { - 'title': 'Python for Data Science', - 'slogan': 'Analyze data with Python', - 'summary_title': 'Data Science with Python', - 'summary': 'Learn Python for data analysis and visualization', - 'description': 'Comprehensive guide to Python libraries for data science.', - 'publisher': 'Science Books Ltd', - 'year_of_publication': '2023', - 'author': 'Sarah Johnson', - 'isbn': '978-1234567893', + 'title': '1984', + 'slogan': 'A dystopian vision of totalitarian control', + 'summary_title': 'George Orwell\'s Warning', + 'summary': 'Big Brother is watching in this chilling dystopia', + 'description': 'In a totalitarian future where truth is manipulated and privacy is nonexistent, Winston Smith begins to question the regime.', + 'publisher': 'Secker & Warburg', + 'year_of_publication': '1949', + 'author': 'George Orwell', + 'isbn': '978-0451524935', 'numnber_of_volume': '1', - 'main_themes': ['python', 'data science', 'analytics'], - 'notable_works': ['Pandas', 'NumPy', 'Matplotlib'], - 'pages_count': '450', + 'main_themes': ['totalitarianism', 'surveillance', 'freedom', 'truth'], + 'notable_works': ['Dystopian Fiction', 'Political Satire'], + 'pages_count': '328', 'file_type': 'pdf', }, { - 'title': 'Machine Learning Basics', - 'slogan': 'Introduction to ML', - 'summary_title': 'ML Fundamentals', - 'summary': 'Get started with machine learning algorithms', - 'description': 'Learn supervised and unsupervised learning techniques.', - 'publisher': 'AI Publishing', - 'year_of_publication': '2023', - 'author': 'Alex Kumar', - 'isbn': '978-1234567894', + 'title': 'The Catcher in the Rye', + 'slogan': 'A teenager\'s journey through alienation and identity', + 'summary_title': 'J.D. Salinger\'s Coming-of-Age Story', + 'summary': 'Holden Caulfield\'s honest and raw narration of teenage angst', + 'description': 'Sixteen-year-old Holden Caulfield has been expelled from yet another school and wanders New York City in a state of alienation.', + 'publisher': 'Little, Brown and Company', + 'year_of_publication': '1951', + 'author': 'J.D. Salinger', + 'isbn': '978-0316769488', 'numnber_of_volume': '1', - 'main_themes': ['machine learning', 'algorithms', 'AI'], - 'notable_works': ['Classification', 'Regression'], - 'pages_count': '520', + 'main_themes': ['adolescence', 'alienation', 'identity', 'innocence'], + 'notable_works': ['Coming-of-Age', 'American Literature'], + 'pages_count': '277', 'file_type': 'pdf', }, { - 'title': 'Cloud Computing Guide', - 'slogan': 'Deploy applications to the cloud', - 'summary_title': 'Cloud Architecture', - 'summary': 'Master cloud platforms and deployment', - 'description': 'Complete guide to AWS, Azure, and Google Cloud.', - 'publisher': 'Cloud Press', - 'year_of_publication': '2023', - 'author': 'Emma Wilson', - 'isbn': '978-1234567895', + 'title': 'Harry Potter and the Philosopher\'s Stone', + 'slogan': 'A young wizard\'s magical adventure begins', + 'summary_title': 'J.K. Rowling\'s Magical World', + 'summary': 'Harry discovers he\'s a wizard and attends Hogwarts School', + 'description': 'Orphaned Harry Potter discovers on his 11th birthday that he is a wizard and begins his magical education at Hogwarts.', + 'publisher': 'Bloomsbury', + 'year_of_publication': '1997', + 'author': 'J.K. Rowling', + 'isbn': '978-0747532699', 'numnber_of_volume': '1', - 'main_themes': ['cloud', 'devops', 'infrastructure'], - 'notable_works': ['AWS', 'Docker', 'Kubernetes'], - 'pages_count': '480', + 'main_themes': ['magic', 'friendship', 'courage', 'good vs evil'], + 'notable_works': ['Fantasy Series', 'Children\'s Literature'], + 'pages_count': '223', 'file_type': 'pdf', }, { - 'title': 'REST API Design', - 'slogan': 'Build scalable APIs', - 'summary_title': 'API Development', - 'summary': 'Design and implement RESTful web services', - 'description': 'Learn API best practices and design patterns.', - 'publisher': 'Web Services Publishing', - 'year_of_publication': '2022', - 'author': 'David Brown', - 'isbn': '978-1234567896', + 'title': 'The Lord of the Rings: The Fellowship of the Ring', + 'slogan': 'An epic tale of adventure and heroism', + 'summary_title': 'J.R.R. Tolkien\'s Masterpiece', + 'summary': 'Frodo\'s quest to destroy the One Ring', + 'description': 'In Middle-earth, the Dark Lord Sauron seeks the One Ring to conquer all. A fellowship forms to prevent this catastrophe.', + 'publisher': 'George Allen & Unwin', + 'year_of_publication': '1954', + 'author': 'J.R.R. Tolkien', + 'isbn': '978-0547928210', 'numnber_of_volume': '1', - 'main_themes': ['api', 'rest', 'web services'], - 'notable_works': ['HTTP Methods', 'Authentication'], - 'pages_count': '340', + 'main_themes': ['adventure', 'friendship', 'courage', 'destiny'], + 'notable_works': ['Epic Fantasy', 'World Building'], + 'pages_count': '423', 'file_type': 'pdf', }, { - 'title': 'Security Best Practices', - 'slogan': 'Secure your applications', - 'summary_title': 'Application Security', - 'summary': 'Essential security practices for developers', - 'description': 'Learn to protect your applications from attacks.', - 'publisher': 'Security Press', - 'year_of_publication': '2023', - 'author': 'Lisa Anderson', - 'isbn': '978-1234567897', + 'title': 'The Alchemist', + 'slogan': 'Follow your dreams and listen to your heart', + 'summary_title': 'Paulo Coelho\'s Inspirational Tale', + 'summary': 'A shepherd boy\'s journey to find his personal legend', + 'description': 'Santiago, an Andalusian shepherd boy, dreams of finding a worldly treasure and embarks on a journey of self-discovery.', + 'publisher': 'HarperOne', + 'year_of_publication': '1988', + 'author': 'Paulo Coelho', + 'isbn': '978-0061122415', 'numnber_of_volume': '1', - 'main_themes': ['security', 'encryption', 'authentication'], - 'notable_works': ['OWASP', 'Cryptography'], - 'pages_count': '400', + 'main_themes': ['dreams', 'destiny', 'spirituality', 'journey'], + 'notable_works': ['Inspirational Fiction', 'Self-Discovery'], + 'pages_count': '208', 'file_type': 'pdf', }, { - 'title': 'Mobile App Development', - 'slogan': 'Build iOS and Android apps', - 'summary_title': 'Mobile Development', - 'summary': 'Cross-platform mobile development guide', - 'description': 'Learn to build native and cross-platform mobile apps.', - 'publisher': 'Mobile Press', - 'year_of_publication': '2023', - 'author': 'Tom Martinez', - 'isbn': '978-1234567898', + 'title': 'The Da Vinci Code', + 'slogan': 'A thriller that uncovers ancient secrets', + 'summary_title': 'Dan Brown\'s Mystery Thriller', + 'summary': 'Robert Langdon races to solve a murder mystery', + 'description': 'Harvard symbologist Robert Langdon becomes involved in a murder mystery that reveals secrets about the Holy Grail.', + 'publisher': 'Doubleday', + 'year_of_publication': '2003', + 'author': 'Dan Brown', + 'isbn': '978-0385504201', 'numnber_of_volume': '1', - 'main_themes': ['mobile', 'ios', 'android'], - 'notable_works': ['React Native', 'Flutter'], - 'pages_count': '490', + 'main_themes': ['mystery', 'conspiracy', 'religion', 'history'], + 'notable_works': ['Thriller', 'Bestseller'], + 'pages_count': '454', 'file_type': 'pdf', }, { - 'title': 'Git and Version Control', - 'slogan': 'Master version control', - 'summary_title': 'Git Workflow', - 'summary': 'Complete guide to Git and collaborative development', - 'description': 'Learn Git commands and best practices.', - 'publisher': 'DevOps Books', - 'year_of_publication': '2022', - 'author': 'Chris Lee', - 'isbn': '978-1234567899', + 'title': 'Sapiens: A Brief History of Humankind', + 'slogan': 'The story of our species from ancient times to modern day', + 'summary_title': 'Yuval Noah Harari\'s Evolutionary History', + 'summary': 'How Homo sapiens became Earth\'s dominant species', + 'description': 'This book explores the history of humankind from the Stone Age to the modern age, examining how we came to dominate Earth.', + 'publisher': 'Harper', + 'year_of_publication': '2014', + 'author': 'Yuval Noah Harari', + 'isbn': '978-0062316097', 'numnber_of_volume': '1', - 'main_themes': ['git', 'version control', 'collaboration'], - 'notable_works': ['Branching', 'Merging'], - 'pages_count': '280', + 'main_themes': ['history', 'evolution', 'civilization', 'humanity'], + 'notable_works': ['Non-fiction', 'Anthropology'], + 'pages_count': '443', 'file_type': 'pdf', }, { - 'title': 'Advanced Python Techniques', - 'slogan': 'Level up your Python skills', - 'summary_title': 'Python Advanced', - 'summary': 'Deep dive into advanced Python concepts', - 'description': 'Explore decorators, generators, and more.', - 'publisher': 'Python Publishers', - 'year_of_publication': '2023', - 'author': 'Rachel Green', - 'isbn': '978-1234567900', - 'numnber_of_volume': '2', - 'main_themes': ['python', 'advanced', 'patterns'], - 'notable_works': ['Decorators', 'Generators', 'Meta-programming'], - 'pages_count': '410', + 'title': 'Educated', + 'slogan': 'A memoir of survival and education', + 'summary_title': 'Tara Westover\'s Life Story', + 'summary': 'A woman\'s quest for knowledge despite her isolated upbringing', + 'description': 'Tara Westover grew up in a survivalist family in rural Idaho and fought to educate herself against all odds.', + 'publisher': 'Random House', + 'year_of_publication': '2018', + 'author': 'Tara Westover', + 'isbn': '978-0399590504', + 'numnber_of_volume': '1', + 'main_themes': ['education', 'family', 'survival', 'identity'], + 'notable_works': ['Memoir', 'Education'], + 'pages_count': '334', 'file_type': 'pdf', }, { - 'title': 'TypeScript Guide', - 'slogan': 'Write type-safe JavaScript', - 'summary_title': 'TypeScript Basics', - 'summary': 'Learn TypeScript for robust web development', - 'description': 'Complete TypeScript guide with practical examples.', - 'publisher': 'JavaScript Press', - 'year_of_publication': '2023', - 'author': 'Kevin White', - 'isbn': '978-1234567901', + 'title': 'Atomic Habits', + 'slogan': 'Small changes, remarkable results', + 'summary_title': 'James Clear\'s Guide to Better Habits', + 'summary': 'How to build good habits and break bad ones', + 'description': 'This book reveals how tiny changes in your daily habits can lead to remarkable transformation in your life.', + 'publisher': 'Avery', + 'year_of_publication': '2018', + 'author': 'James Clear', + 'isbn': '978-0735211292', 'numnber_of_volume': '1', - 'main_themes': ['typescript', 'javascript', 'types'], - 'notable_works': ['Interfaces', 'Generics'], - 'pages_count': '360', + 'main_themes': ['habits', 'productivity', 'self-improvement', 'psychology'], + 'notable_works': ['Self-Help', 'Psychology'], + 'pages_count': '320', 'file_type': 'pdf', }, { - 'title': 'React Deep Dive', - 'slogan': 'Master React framework', - 'summary_title': 'React Advanced', - 'summary': 'Advanced React concepts and patterns', - 'description': 'Learn hooks, context, and performance optimization.', - 'publisher': 'Frontend Press', - 'year_of_publication': '2023', - 'author': 'Nina Patel', - 'isbn': '978-1234567902', + 'title': 'The Psychology of Money', + 'slogan': 'Timeless lessons on wealth, greed, and happiness', + 'summary_title': 'Morgan Housel\'s Financial Wisdom', + 'summary': 'Understanding the strange ways people think about money', + 'description': 'This book explores the psychology behind our financial decisions and how our behavior often defies logic.', + 'publisher': 'Harriman House', + 'year_of_publication': '2020', + 'author': 'Morgan Housel', + 'isbn': '978-0857197689', 'numnber_of_volume': '1', - 'main_themes': ['react', 'javascript', 'frontend'], - 'notable_works': ['Hooks', 'Context API', 'Performance'], - 'pages_count': '470', + 'main_themes': ['finance', 'psychology', 'behavior', 'wealth'], + 'notable_works': ['Finance', 'Psychology'], + 'pages_count': '256', 'file_type': 'pdf', }, { - 'title': 'Django for Beginners', - 'slogan': 'Build web apps with Django', - 'summary_title': 'Django Basics', - 'summary': 'Learn Django framework from scratch', - 'description': 'Complete beginner guide to Django web development.', - 'publisher': 'Django Press', - 'year_of_publication': '2023', - 'author': 'Oscar Torres', - 'isbn': '978-1234567903', + 'title': 'Thinking, Fast and Slow', + 'slogan': 'The groundbreaking investigation of how we think', + 'summary_title': 'Daniel Kahneman\'s Cognitive Psychology', + 'summary': 'How our minds work in two different modes', + 'description': 'Nobel Prize winner Daniel Kahneman explores the two systems that drive how we think: fast, intuitive thinking and slow, deliberate thinking.', + 'publisher': 'Farrar, Straus and Giroux', + 'year_of_publication': '2011', + 'author': 'Daniel Kahneman', + 'isbn': '978-0374533557', 'numnber_of_volume': '1', - 'main_themes': ['django', 'python', 'web development'], - 'notable_works': ['Models', 'Views', 'Templates'], - 'pages_count': '440', + 'main_themes': ['psychology', 'decision-making', 'cognitive bias', 'behavior'], + 'notable_works': ['Psychology', 'Nobel Prize'], + 'pages_count': '499', 'file_type': 'pdf', }, { - 'title': 'Testing and QA', - 'slogan': 'Write better tests', - 'summary_title': 'Testing Strategies', - 'summary': 'Unit testing, integration testing and automation', - 'description': 'Comprehensive guide to software testing.', - 'publisher': 'QA Press', - 'year_of_publication': '2022', - 'author': 'Patricia Davis', - 'isbn': '978-1234567904', + 'title': 'The Silent Patient', + 'slogan': 'A woman refuses to speak after committing murder', + 'summary_title': 'Alex Michaelides\' Psychological Thriller', + 'summary': 'A psychotherapist becomes obsessed with his patient\'s silence', + 'description': 'Alicia Berenson\'s refusal to speak after allegedly murdering her husband becomes the ultimate mystery for psychotherapist Theo Faber.', + 'publisher': 'Celadon Books', + 'year_of_publication': '2019', + 'author': 'Alex Michaelides', + 'isbn': '978-1250301697', 'numnber_of_volume': '1', - 'main_themes': ['testing', 'qa', 'automation'], - 'notable_works': ['Unit Tests', 'Integration Tests'], - 'pages_count': '350', + 'main_themes': ['mystery', 'psychology', 'silence', 'obsession'], + 'notable_works': ['Thriller', 'Psychological Fiction'], + 'pages_count': '336', 'file_type': 'pdf', }, { - 'title': 'Docker and Containerization', - 'slogan': 'Containerize your applications', - 'summary_title': 'Docker Essentials', - 'summary': 'Docker fundamentals and best practices', - 'description': 'Learn containerization with Docker and Compose.', - 'publisher': 'Container Press', - 'year_of_publication': '2023', - 'author': 'Victor Lopez', - 'isbn': '978-1234567905', + 'title': 'The Midnight Library', + 'slogan': 'Between life and death, every choice matters', + 'summary_title': 'Matt Haig\'s Philosophical Fiction', + 'summary': 'A woman gets to live out different versions of her life', + 'description': 'Between life and death, Nora Seed finds herself in a library where she can try out different lives she might have lived.', + 'publisher': 'Canongate Books', + 'year_of_publication': '2020', + 'author': 'Matt Haig', + 'isbn': '978-0525559474', 'numnber_of_volume': '1', - 'main_themes': ['docker', 'containers', 'devops'], - 'notable_works': ['Images', 'Containers', 'Docker Compose'], - 'pages_count': '400', + 'main_themes': ['life choices', 'regret', 'possibility', 'self-discovery'], + 'notable_works': ['Philosophical Fiction', 'Contemporary'], + 'pages_count': '288', 'file_type': 'pdf', }, { - 'title': 'Microservices Architecture', - 'slogan': 'Build scalable systems', - 'summary_title': 'Microservices Design', - 'summary': 'Design and implement microservices', - 'description': 'Guide to building distributed microservice systems.', - 'publisher': 'Architecture Press', - 'year_of_publication': '2023', - 'author': 'Wendy Harris', - 'isbn': '978-1234567906', + 'title': 'Where the Crawdads Sing', + 'slogan': 'A mystery wrapped in a coming-of-age story', + 'summary_title': 'Delia Owens\' Natural Mystery', + 'summary': 'A young woman raised by the marsh becomes a suspect in a murder', + 'description': 'Kya Clark, the "Marsh Girl," becomes a suspect in a murder while living in isolation in the North Carolina marshes.', + 'publisher': 'G.P. Putnam\'s Sons', + 'year_of_publication': '2018', + 'author': 'Delia Owens', + 'isbn': '978-0735219090', 'numnber_of_volume': '1', - 'main_themes': ['microservices', 'architecture', 'distributed'], - 'notable_works': ['Service Design', 'Communication Patterns'], - 'pages_count': '510', + 'main_themes': ['nature', 'isolation', 'mystery', 'coming-of-age'], + 'notable_works': ['Literary Fiction', 'Mystery'], + 'pages_count': '384', 'file_type': 'pdf', }, { - 'title': 'GraphQL Mastery', - 'slogan': 'Query language for APIs', - 'summary_title': 'GraphQL Guide', - 'summary': 'Learn GraphQL query language and execution', - 'description': 'Complete guide to GraphQL API development.', - 'publisher': 'GraphQL Press', - 'year_of_publication': '2023', - 'author': 'Xavier Knight', - 'isbn': '978-1234567907', + 'title': 'The Seven Husbands of Evelyn Hugo', + 'slogan': 'A reclusive Hollywood icon tells her story', + 'summary_title': 'Taylor Jenkins Reid\'s Glamorous Tale', + 'summary': 'A journalist uncovers the secrets of a legendary star', + 'description': 'Reclusive Hollywood icon Evelyn Hugo chooses an unknown journalist to tell her life story and the truth about her seven marriages.', + 'publisher': 'Washington Square Press', + 'year_of_publication': '2017', + 'author': 'Taylor Jenkins Reid', + 'isbn': '978-1501139239', 'numnber_of_volume': '1', - 'main_themes': ['graphql', 'api', 'query language'], - 'notable_works': ['Queries', 'Mutations', 'Subscriptions'], - 'pages_count': '380', + 'main_themes': ['hollywood', 'secrets', 'identity', 'love'], + 'notable_works': ['Historical Fiction', 'Romance'], + 'pages_count': '400', 'file_type': 'pdf', }, { - 'title': 'Performance Optimization', - 'slogan': 'Make your code faster', - 'summary_title': 'Optimization Techniques', - 'summary': 'Optimize application performance', - 'description': 'Strategies for improving code and system performance.', - 'publisher': 'Performance Press', - 'year_of_publication': '2023', - 'author': 'Yvonne Robinson', - 'isbn': '978-1234567908', + 'title': 'Circe', + 'slogan': 'The story of the witch from The Odyssey', + 'summary_title': 'Madeline Miller\'s Mythological Tale', + 'summary': 'A mortal woman becomes a goddess and discovers her power', + 'description': 'Circe, daughter of the sun god Helios, is banished to an island where she hones her witchcraft and encounters legendary figures.', + 'publisher': 'Little, Brown and Company', + 'year_of_publication': '2018', + 'author': 'Madeline Miller', + 'isbn': '978-0316556347', 'numnber_of_volume': '1', - 'main_themes': ['performance', 'optimization', 'caching'], - 'notable_works': ['Profiling', 'Caching', 'Monitoring'], - 'pages_count': '360', + 'main_themes': ['mythology', 'power', 'identity', 'transformation'], + 'notable_works': ['Mythological Fiction', 'Feminism'], + 'pages_count': '393', 'file_type': 'pdf', }, { - 'title': 'Clean Code Practices', - 'slogan': 'Write maintainable code', - 'summary_title': 'Code Quality', - 'summary': 'Best practices for writing clean code', - 'description': 'Learn coding standards and refactoring techniques.', - 'publisher': 'Code Press', - 'year_of_publication': '2023', - 'author': 'Zoe Walker', - 'isbn': '978-1234567909', + 'title': 'Normal People', + 'slogan': 'A story of first love and complicated friendship', + 'summary_title': 'Sally Rooney\'s Contemporary Romance', + 'summary': 'Two young people navigate love and connection', + 'description': 'Marianne and Connell\'s relationship evolves from high school classmates to university students, exploring themes of love, class, and mental health.', + 'publisher': 'Faber & Faber', + 'year_of_publication': '2018', + 'author': 'Sally Rooney', + 'isbn': '978-0571334650', 'numnber_of_volume': '1', - 'main_themes': ['clean code', 'best practices', 'refactoring'], - 'notable_works': ['SOLID Principles', 'Design Patterns'], - 'pages_count': '430', + 'main_themes': ['love', 'friendship', 'class', 'mental health'], + 'notable_works': ['Contemporary Fiction', 'Romance'], + 'pages_count': '304', 'file_type': 'pdf', }, { - 'title': 'Artificial Intelligence Fundamentals', - 'slogan': 'Understanding AI and ML', - 'summary_title': 'AI Basics', - 'summary': 'Foundational concepts of artificial intelligence', - 'description': 'Introduction to AI, machine learning and deep learning.', - 'publisher': 'AI Academy', - 'year_of_publication': '2023', - 'author': 'Benjamin Foster', - 'isbn': '978-1234567910', + 'title': 'The Vanishing Half', + 'slogan': 'Twin sisters choose different racial identities', + 'summary_title': 'Brit Bennett\'s Family Saga', + 'summary': 'The story of twin sisters who grow up to live in two very different worlds', + 'description': 'The Vignes twin sisters grow up in a small black community but choose to live in two very different racial worlds—one white and one black.', + 'publisher': 'Riverhead Books', + 'year_of_publication': '2020', + 'author': 'Brit Bennett', + 'isbn': '978-0525536963', 'numnber_of_volume': '1', - 'main_themes': ['ai', 'machine learning', 'neural networks'], - 'notable_works': ['Neural Networks', 'Deep Learning'], - 'pages_count': '520', + 'main_themes': ['race', 'identity', 'family', 'belonging'], + 'notable_works': ['Literary Fiction', 'Social Commentary'], + 'pages_count': '352', 'file_type': 'pdf', }, ] - # Book cover images (cycling through 4 images) - image_paths = [ - 'seeds/images/lib-book1.jpg', - 'seeds/images/lib-book2.jpg', - 'seeds/images/lib-book3.jpg', - 'seeds/images/lib-book4.jpg', - ] - - # Category IDs and Collection IDs - category_ids = [1, 2, 3, 4, 5, 15, 16, 17, 18, 19, 20] - collection_ids = [1, 2, 3, 4, 5, 6, 13, 14, 15] - + # 2. CREATE NEW DATA created_books = [] - image_index = 0 - - self.stdout.write(self.style.SUCCESS('Starting book creation...')) - - # Create books + for idx, book_info in enumerate(book_data): try: - # Create slug if not present slug = slugify(book_info['title']) - # Create the book - book = Book.objects.create( + # Create the book instance (WITHOUT the image first) + book = Book( title=book_info['title'], slug=slug, slogan=book_info['slogan'], @@ -400,29 +400,44 @@ class Command(BaseCommand): author=book_info['author'], isbn=book_info['isbn'], numnber_of_volume=book_info['numnber_of_volume'], - language=language, # Pass Language instance + language=language, main_themes=book_info['main_themes'], notable_works=book_info['notable_works'], pages_count=book_info['pages_count'], file_type=book_info['file_type'], status=True, pin=True, - thumbnail=image_paths[image_index % len(image_paths)], ) - # Cycle through images - image_index += 1 - created_books.append(book) + # HANDLE THE IMAGE (The Magic Step) + # Pick an image filename + img_name = image_filenames[idx % len(image_filenames)] + img_full_path = os.path.join(seeds_path, img_name) - self.stdout.write( - self.style.SUCCESS(f'✓ Created book: {book.title}') - ) + if os.path.exists(img_full_path): + with open(img_full_path, 'rb') as f: + # This copies the file from /seeds/ to /media/ + book.thumbnail.save(img_name, File(f), save=False) + else: + self.stdout.write(self.style.WARNING(f"Image not found: {img_full_path}")) + + # Now save the book to DB + book.save() + created_books.append(book) + + self.stdout.write(self.style.SUCCESS(f'✓ Created: {book.title}')) except Exception as e: - self.stdout.write( - self.style.ERROR(f'✗ Error creating book {book_info["title"]}: {str(e)}') - ) - continue + self.stdout.write(self.style.ERROR(f'Error: {e}')) + + + # Category IDs and Collection IDs + category_ids = [1, 2, 3, 4, 5, 15, 16, 17, 18, 19, 20] + collection_ids = [1, 2, 3, 4, 5, 6, 13, 14, 15] + + created_books = [] + + self.stdout.write(self.style.SUCCESS('Starting book creation...')) # Connect books with categories self.stdout.write(self.style.SUCCESS('\nConnecting books to categories...')) diff --git a/entrypoint.sh b/entrypoint.sh index a37faf7..cfd9e6b 100755 --- a/entrypoint.sh +++ b/entrypoint.sh @@ -2,7 +2,9 @@ sleep 20 python manage.py migrate -python manage.py seed_images +# python manage.py seed_images python manage.py collectstatic --noinput +python manage.py populate_books + exec "$@"