Skip to content

Instantly share code, notes, and snippets.

@ggamit1
Created November 2, 2019 01:50
Show Gist options
  • Save ggamit1/a45ddfbc71a83fc5ecc0f1937a6f6571 to your computer and use it in GitHub Desktop.
Save ggamit1/a45ddfbc71a83fc5ecc0f1937a6f6571 to your computer and use it in GitHub Desktop.
django Hello
from django.contrib import admin
from .models import Question
admin.site.register(Question)
from django.apps import AppConfig
class PollsConfig(AppConfig):
name = 'polls'
# Generated by Django 3.1 on 2019-10-20 17:54
from django.db import migrations, models
import django.db.models.deletion
class Migration(migrations.Migration):
initial = True
dependencies = [
]
operations = [
migrations.CreateModel(
name='Question',
fields=[
('id', models.AutoField(auto_created=True, primary_key=True, serialize=False, verbose_name='ID')),
('question_text', models.CharField(max_length=200)),
('pub_date', models.DateTimeField(verbose_name='date published')),
],
),
migrations.CreateModel(
name='Choice',
fields=[
('id', models.AutoField(auto_created=True, primary_key=True, serialize=False, verbose_name='ID')),
('choice_text', models.CharField(max_length=200)),
('votes', models.IntegerField(default=0)),
('question', models.ForeignKey(on_delete=django.db.models.deletion.CASCADE, to='polls.Question')),
],
),
]
import datetime
from django.db import models
from django.utils import timezone
class Question(models.Model):
# ...
def was_published_recently(self):
return self.pub_date >= timezone.now() - datetime.timedelta(days=1)
from django.test import TestCase
# Create your tests here.
from django.urls import path
from . import views
urlpatterns = [
path('', views.index, name='index'),
]
from django.http import HttpResponse
def index(request):
print("jdfkdjfjdfjdjflsd")
return HttpResponse("Hello,sh pycharm.sh world. You're at the polls index.")
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment