@@ -488,10 +488,13 @@ class Migration(migrations.Migration):
488488 ('id' , models .BigAutoField (auto_created = True , primary_key = True , serialize = False , verbose_name = 'ID' )),
489489 ('category' , models .CharField (max_length = 200 )),
490490 ('total_points' , models .IntegerField (default = 0 )),
491+ ('rank' , models .IntegerField (default = 0 )),
492+ ('last_updated' , models .DateTimeField (auto_now = True )),
491493 ('user' , models .ForeignKey (on_delete = django .db .models .deletion .CASCADE , to = settings .AUTH_USER_MODEL )),
492494 ],
493495 options = {
494- 'ordering' : ['-total_points' ],
496+ 'ordering' : ['-total_points' , 'rank' ],
497+ 'unique_together' : {('user' , 'category' )},
495498 },
496499 ),
497500 migrations .CreateModel (
@@ -582,4 +585,121 @@ class Migration(migrations.Migration):
582585 'unique_together' : {('name' , 'parent' , 'owner' )},
583586 },
584587 ),
588+ # ===== CODE EXECUTION MODELS =====
589+ migrations .CreateModel (
590+ name = 'CodeTemplate' ,
591+ fields = [
592+ ('id' , models .BigAutoField (auto_created = True , primary_key = True , serialize = False , verbose_name = 'ID' )),
593+ ('title' , models .CharField (max_length = 200 )),
594+ ('description' , models .TextField ()),
595+ ('category' , models .CharField (choices = [('basics' , 'Python Basics' ), ('data_structures' , 'Data Structures' ), ('algorithms' , 'Algorithms' ), ('oop' , 'Object-Oriented Programming' ), ('file_handling' , 'File Handling' ), ('web_scraping' , 'Web Scraping' ), ('data_analysis' , 'Data Analysis' ), ('machine_learning' , 'Machine Learning' ), ('security' , 'Security' ), ('networking' , 'Networking' )], max_length = 20 )),
596+ ('difficulty' , models .CharField (choices = [('beginner' , 'Beginner' ), ('intermediate' , 'Intermediate' ), ('advanced' , 'Advanced' )], max_length = 15 )),
597+ ('template_code' , models .TextField ()),
598+ ('expected_output' , models .TextField (blank = True , null = True )),
599+ ('hints' , models .TextField (blank = True , null = True )),
600+ ('is_active' , models .BooleanField (default = True )),
601+ ('created_at' , models .DateTimeField (auto_now_add = True )),
602+ ('updated_at' , models .DateTimeField (auto_now = True )),
603+ ],
604+ options = {
605+ 'ordering' : ['category' , 'difficulty' , 'title' ],
606+ },
607+ ),
608+ migrations .CreateModel (
609+ name = 'CompilerSettings' ,
610+ fields = [
611+ ('id' , models .BigAutoField (auto_created = True , primary_key = True , serialize = False , verbose_name = 'ID' )),
612+ ('max_execution_time' , models .IntegerField (default = 5 )),
613+ ('max_memory_limit' , models .IntegerField (default = 128 )),
614+ ('max_code_length' , models .IntegerField (default = 1000 )),
615+ ('allowed_modules' , models .JSONField (default = list )),
616+ ('is_active' , models .BooleanField (default = True )),
617+ ('created_at' , models .DateTimeField (auto_now_add = True )),
618+ ('updated_at' , models .DateTimeField (auto_now = True )),
619+ ],
620+ ),
621+ migrations .CreateModel (
622+ name = 'CodeExecution' ,
623+ fields = [
624+ ('id' , models .BigAutoField (auto_created = True , primary_key = True , serialize = False , verbose_name = 'ID' )),
625+ ('language' , models .CharField (default = 'python' , max_length = 20 )),
626+ ('code' , models .TextField ()),
627+ ('input_data' , models .TextField (blank = True , null = True )),
628+ ('output' , models .TextField (blank = True , null = True )),
629+ ('error_message' , models .TextField (blank = True , null = True )),
630+ ('execution_time' , models .FloatField (default = 0.0 )),
631+ ('memory_used' , models .IntegerField (default = 0 )),
632+ ('is_successful' , models .BooleanField (default = False )),
633+ ('created_at' , models .DateTimeField (auto_now_add = True )),
634+ ('ip_address' , models .GenericIPAddressField (blank = True , null = True )),
635+ ('user' , models .ForeignKey (blank = True , null = True , on_delete = django .db .models .deletion .CASCADE , to = settings .AUTH_USER_MODEL )),
636+ ],
637+ options = {
638+ 'ordering' : ['-created_at' ],
639+ },
640+ ),
641+ migrations .CreateModel (
642+ name = 'CodeSubmission' ,
643+ fields = [
644+ ('id' , models .BigAutoField (auto_created = True , primary_key = True , serialize = False , verbose_name = 'ID' )),
645+ ('user_code' , models .TextField ()),
646+ ('is_correct' , models .BooleanField (default = False )),
647+ ('execution_time' , models .FloatField (default = 0.0 )),
648+ ('submitted_at' , models .DateTimeField (auto_now_add = True )),
649+ ('template' , models .ForeignKey (on_delete = django .db .models .deletion .CASCADE , to = 'home.codetemplate' )),
650+ ('user' , models .ForeignKey (on_delete = django .db .models .deletion .CASCADE , to = settings .AUTH_USER_MODEL )),
651+ ],
652+ options = {
653+ 'ordering' : ['-submitted_at' ],
654+ 'unique_together' : {('user' , 'template' )},
655+ },
656+ ),
657+ # ===== QUIZ MODELS =====
658+ migrations .CreateModel (
659+ name = 'UserScore' ,
660+ fields = [
661+ ('id' , models .BigAutoField (auto_created = True , primary_key = True , serialize = False , verbose_name = 'ID' )),
662+ ('category' , models .CharField (choices = [('network' , 'Network Security' ), ('web' , 'Web Application Security' ), ('crypto' , 'Cryptography' ), ('general' , 'General Knowledge' ), ('python' , 'Python' ), ('javascript' , 'JavaScript' ), ('html_css' , 'HTML & CSS' ), ('web_security' , 'Web Security' ), ('reverse_engineering' , 'Reverse Engineering' ), ('forensics' , 'Forensics' ), ('binary_exploitation' , 'Binary Exploitation' ), ('linux' , 'Linux' ), ('algorithms' , 'Algorithms' ), ('data_structures' , 'Data Structures' ), ('databases' , 'Databases' ), ('regex' , 'Regex' ), ('secure_coding' , 'Secure Coding' ), ('logic_reasoning' , 'Logic & Reasoning' ), ('misc' , 'Miscellaneous' )], max_length = 20 )),
663+ ('score' , models .IntegerField (default = 0 )),
664+ ('quiz_completed_at' , models .DateTimeField (auto_now_add = True )),
665+ ('user' , models .ForeignKey (on_delete = django .db .models .deletion .CASCADE , to = settings .AUTH_USER_MODEL )),
666+ ],
667+ options = {
668+ 'ordering' : ['-score' , '-quiz_completed_at' ],
669+ 'unique_together' : {('user' , 'category' )},
670+ },
671+ ),
672+ migrations .CreateModel (
673+ name = 'Quiz' ,
674+ fields = [
675+ ('id' , models .BigAutoField (auto_created = True , primary_key = True , serialize = False , verbose_name = 'ID' )),
676+ ('category' , models .CharField (choices = [('network' , 'Network Security' ), ('web' , 'Web Application Security' ), ('crypto' , 'Cryptography' ), ('general' , 'General Knowledge' ), ('python' , 'Python' ), ('javascript' , 'JavaScript' ), ('html_css' , 'HTML & CSS' ), ('web_security' , 'Web Security' ), ('reverse_engineering' , 'Reverse Engineering' ), ('forensics' , 'Forensics' ), ('binary_exploitation' , 'Binary Exploitation' ), ('linux' , 'Linux' ), ('algorithms' , 'Algorithms' ), ('data_structures' , 'Data Structures' ), ('databases' , 'Databases' ), ('regex' , 'Regex' ), ('secure_coding' , 'Secure Coding' ), ('logic_reasoning' , 'Logic & Reasoning' ), ('misc' , 'Miscellaneous' )], max_length = 20 )),
677+ ('started_at' , models .DateTimeField (auto_now_add = True )),
678+ ('completed_at' , models .DateTimeField (blank = True , null = True )),
679+ ('is_completed' , models .BooleanField (default = False )),
680+ ('total_score' , models .IntegerField (default = 0 )),
681+ ('questions_answered' , models .IntegerField (default = 0 )),
682+ ('current_question_index' , models .IntegerField (default = 0 )),
683+ ('user' , models .ForeignKey (on_delete = django .db .models .deletion .CASCADE , to = settings .AUTH_USER_MODEL )),
684+ ],
685+ options = {
686+ 'ordering' : ['-started_at' ],
687+ },
688+ ),
689+ migrations .CreateModel (
690+ name = 'QuizQuestion' ,
691+ fields = [
692+ ('id' , models .BigAutoField (auto_created = True , primary_key = True , serialize = False , verbose_name = 'ID' )),
693+ ('question_order' , models .IntegerField ()),
694+ ('user_answer' , models .CharField (blank = True , max_length = 200 , null = True )),
695+ ('is_correct' , models .BooleanField (default = False )),
696+ ('answered_at' , models .DateTimeField (blank = True , null = True )),
697+ ('challenge' , models .ForeignKey (on_delete = django .db .models .deletion .CASCADE , to = 'home.cyberchallenge' )),
698+ ('quiz' , models .ForeignKey (on_delete = django .db .models .deletion .CASCADE , related_name = 'questions' , to = 'home.quiz' )),
699+ ],
700+ options = {
701+ 'ordering' : ['question_order' ],
702+ 'unique_together' : {('quiz' , 'question_order' )},
703+ },
704+ ),
585705 ]
0 commit comments