mirror of
				https://github.com/DerTyp7/tealcode-django-python.git
				synced 2025-10-31 05:07:08 +01:00 
			
		
		
		
	added models
This commit is contained in:
		| @@ -1,3 +1,5 @@ | |||||||
| from django.contrib import admin | from django.contrib import admin | ||||||
|  | from .models import Category, Topic | ||||||
|  |  | ||||||
| # Register your models here. | admin.site.register(Category) | ||||||
|  | admin.site.register(Topic) | ||||||
							
								
								
									
										23
									
								
								TealCode/main/migrations/0001_initial.py
									
									
									
									
									
										Normal file
									
								
							
							
						
						
									
										23
									
								
								TealCode/main/migrations/0001_initial.py
									
									
									
									
									
										Normal file
									
								
							| @@ -0,0 +1,23 @@ | |||||||
|  | # Generated by Django 3.2.9 on 2021-11-10 07:58 | ||||||
|  |  | ||||||
|  | from django.db import migrations, models | ||||||
|  | import django.utils.timezone | ||||||
|  |  | ||||||
|  |  | ||||||
|  | class Migration(migrations.Migration): | ||||||
|  |  | ||||||
|  |     initial = True | ||||||
|  |  | ||||||
|  |     dependencies = [ | ||||||
|  |     ] | ||||||
|  |  | ||||||
|  |     operations = [ | ||||||
|  |         migrations.CreateModel( | ||||||
|  |             name='Category', | ||||||
|  |             fields=[ | ||||||
|  |                 ('id', models.BigAutoField(auto_created=True, primary_key=True, serialize=False, verbose_name='ID')), | ||||||
|  |                 ('title', models.CharField(max_length=100)), | ||||||
|  |                 ('date_created', models.DateTimeField(default=django.utils.timezone.now)), | ||||||
|  |             ], | ||||||
|  |         ), | ||||||
|  |     ] | ||||||
							
								
								
									
										30
									
								
								TealCode/main/migrations/0002_auto_20211110_0912.py
									
									
									
									
									
										Normal file
									
								
							
							
						
						
									
										30
									
								
								TealCode/main/migrations/0002_auto_20211110_0912.py
									
									
									
									
									
										Normal file
									
								
							| @@ -0,0 +1,30 @@ | |||||||
|  | # Generated by Django 3.2.9 on 2021-11-10 08:12 | ||||||
|  |  | ||||||
|  | from django.db import migrations, models | ||||||
|  | import django.db.models.deletion | ||||||
|  | import django.utils.timezone | ||||||
|  |  | ||||||
|  |  | ||||||
|  | class Migration(migrations.Migration): | ||||||
|  |  | ||||||
|  |     dependencies = [ | ||||||
|  |         ('main', '0001_initial'), | ||||||
|  |     ] | ||||||
|  |  | ||||||
|  |     operations = [ | ||||||
|  |         migrations.AlterField( | ||||||
|  |             model_name='category', | ||||||
|  |             name='title', | ||||||
|  |             field=models.CharField(max_length=100, unique=True), | ||||||
|  |         ), | ||||||
|  |         migrations.CreateModel( | ||||||
|  |             name='Topic', | ||||||
|  |             fields=[ | ||||||
|  |                 ('id', models.BigAutoField(auto_created=True, primary_key=True, serialize=False, verbose_name='ID')), | ||||||
|  |                 ('title', models.CharField(max_length=200)), | ||||||
|  |                 ('code_text', models.TextField()), | ||||||
|  |                 ('date_created', models.DateTimeField(default=django.utils.timezone.now)), | ||||||
|  |                 ('category', models.ForeignKey(on_delete=django.db.models.deletion.CASCADE, to='main.category')), | ||||||
|  |             ], | ||||||
|  |         ), | ||||||
|  |     ] | ||||||
| @@ -1,3 +1,20 @@ | |||||||
| from django.db import models | from django.db import models | ||||||
|  | from django.db.models.fields.related import ForeignKey | ||||||
|  | from django.utils import timezone | ||||||
|  |  | ||||||
| # Create your models here. | class Category(models.Model): | ||||||
|  |     title = models.CharField(max_length=100, unique=True) | ||||||
|  |     date_created = models.DateTimeField(default=timezone.now) | ||||||
|  |  | ||||||
|  |     def __str__(self): | ||||||
|  |         return self.title | ||||||
|  |  | ||||||
|  |  | ||||||
|  | class Topic(models.Model): | ||||||
|  |     title = models.CharField(max_length= 200) | ||||||
|  |     code_text = models.TextField() | ||||||
|  |     date_created = models.DateTimeField(default=timezone.now) | ||||||
|  |     category = models.ForeignKey(Category, on_delete=models.CASCADE) | ||||||
|  |  | ||||||
|  |     def __str__(self): | ||||||
|  |         return self.category.title + " - " + self.title | ||||||
|   | |||||||
| @@ -1,5 +1,9 @@ | |||||||
| {% extends "main/base.html" %} | {% extends "main/base.html" %} | ||||||
| {% block content %} | {% block content %} | ||||||
|  |      | ||||||
|  |     <div id="main-headline"> | ||||||
|  |         <h2>{{ category_obj.title }}</h2> | ||||||
|  |     </div> | ||||||
|     <div id="list"> |     <div id="list"> | ||||||
|         <div class="list-item"> |         <div class="list-item"> | ||||||
|             <img src="c_icon.png"/> |             <img src="c_icon.png"/> | ||||||
|   | |||||||
| @@ -1,12 +1,11 @@ | |||||||
| {% extends "main/base.html" %} | {% extends "main/base.html" %} | ||||||
| {% block content %} | {% block content %} | ||||||
|     <div id="main-headline"> |     <div id="main-headline"> | ||||||
|                 <h2>How To Convert a String to Int</h2> |                 <h2>{{ title }}</h2> | ||||||
|             </div> |             </div> | ||||||
|  |  | ||||||
|   <div id="main-content-code"> |     <div id="main-content-code"> | ||||||
|                 <pre><code  style="padding-top: 5px; padding-bottom: 5px;"class="language-c">int c; |         <pre><code  style="padding-top: 5px; padding-bottom: 5px;"class="language-{{category_title}}">{{code}}</code></pre> | ||||||
|     c = int.c * t/g;</code></pre> |     </div> | ||||||
|             </div> |  | ||||||
|  |  | ||||||
| {% endblock content %} | {% endblock content %} | ||||||
| @@ -1,10 +1,36 @@ | |||||||
| from django.shortcuts import render | from django.shortcuts import render, redirect | ||||||
|  | from .models import Category, Topic | ||||||
|  |  | ||||||
| def index(req): | def index(req): | ||||||
|     return render(req, "main/index.html") |     return render(req, "main/index.html") | ||||||
|  |  | ||||||
| def topic(req, category, topic): | def topic(req, category, topic): | ||||||
|     return render(req, "main/topic.html") |  | ||||||
|  |     if topic and category: | ||||||
|  |         category_obj = Category.objects.filter(title = category).first() | ||||||
|  |         if category_obj: | ||||||
|  |             topic_obj = Topic.objects.filter(title=topic, category = category_obj).first() | ||||||
|  |             if topic_obj: | ||||||
|  |                 context = { | ||||||
|  |                     'title': topic_obj.title, | ||||||
|  |                     'code': topic_obj.code_text, | ||||||
|  |                     'category_title': category_obj.title, | ||||||
|  |                 } | ||||||
|  |  | ||||||
|  |                 return render(req, "main/topic.html", context) | ||||||
|  |  | ||||||
|  |     return redirect("main-index") | ||||||
|  |  | ||||||
|  |      | ||||||
|  |  | ||||||
| def category(req, category): | def category(req, category): | ||||||
|     return render(req, "main/category.html") |      | ||||||
|  |     if category: | ||||||
|  |         category_obj = Category.objects.filter(title = category).first() | ||||||
|  |         if category_obj: | ||||||
|  |             return render(req, "main/category.html", {'category_obj': category_obj}) | ||||||
|  |          | ||||||
|  |      | ||||||
|  |     return redirect("main-index") | ||||||
|  |  | ||||||
|  |  | ||||||
|   | |||||||
		Reference in New Issue
	
	Block a user
	 DerTyp187
					DerTyp187