Skip to content

Instantly share code, notes, and snippets.

@namantw
namantw / urls.py
Last active January 13, 2019 13:05
from django.contrib import admin
from django.urls import path
from selection import views
urlpatterns = [
path('admin/', admin.site.urls), # automatically created by django
path('', views.home, name='register'), # when someone will access www.yourpage.com/ it will send request to 'home' view
path('reg_form/', views.register, name='reg_form'),
path('login/', views.user_login, name='login'),
@namantw
namantw / views.py
Last active January 13, 2019 13:05
from django.shortcuts import render, redirect
from .forms import UserForm, RegistrationForm, LoginForm, SelectionForm
from django.http import HttpResponse, Http404
from selection.models import Student, Room, Hostel
from django.contrib.auth import authenticate, login, logout
from django.contrib.auth.decorators import login_required
def home(request): # the function will take request as input
return render(request, 'home.html') # the function then renders an html page template called home.html
from django import forms
from django.contrib.auth.models import User
from django.contrib.auth.forms import UserCreationForm
from .models import Student
from django import forms
class UserForm(UserCreationForm):
class Meta:
model = User
@namantw
namantw / models.py
Created July 5, 2018 09:35
Models used for hostel management system
from django.db import models
from django.contrib.auth.models import User
class Student(models.Model):
user = models.OneToOneField(
User,
default=None,
null=True,
on_delete=models.CASCADE)
@namantw
namantw / dial.py
Last active March 24, 2018 20:02
Parse command-line and show a dialer popup
# Creator : Naman Tiwari (namantw)
# To run : Make sure Python 3 is installed and PyQt5 is installed
# Test : python dial.py <phone number>
# For example : 'python dial.py +9872621111'
from PyQt5.QtCore import Qt
from PyQt5.QtWidgets import (QApplication, QGridLayout, QLayout, QLineEdit,
QSizePolicy, QToolButton, QWidget)
class Button(QToolButton):