Skip to content

Instantly share code, notes, and snippets.

@dura0ok
Created February 13, 2018 16:25
Show Gist options
  • Save dura0ok/0c8e0b0291773630c5798ed55018a120 to your computer and use it in GitHub Desktop.
Save dura0ok/0c8e0b0291773630c5798ed55018a120 to your computer and use it in GitHub Desktop.
from django.db import models
from django.utils import timezone
from django.contrib.auth.models import User
class Post(models.Model):
author = models.ForeignKey('auth.User')
title = models.CharField(max_length=200)
text = models.TextField()
image = models.ImageField(upload_to='img')
created_date = models.DateTimeField(
default=timezone.now)
published_date = models.DateTimeField(
blank=True, null=True)
def publish(self):
self.published_date = timezone.now()
self.save()
def __str__(self):
return self.title
class Client(models.Model):
user = models.OneToOneField(User)
user_photo = models.ImageField(upload_to='img')
<!DOCTYPE html>
<html lang="en">
<head>
{% load staticfiles %}
<link rel="stylesheet" href="{% static "css/style.css" %}">
<meta charset="UTF-8">
<title>Title</title>
</head>
<body>
<header>
<h3>Блог-Просто о мире IT!</h3>
<ul>
{% if user.is_authenticated %}
<li><a href="{% url 'post_new' %}">Добавить запись</a></li>
</ul>
<img width="80" height="50" src="{{ user_photo.url }}">
<div class="user">
<p>Привет,<a href="#">{{ user.username|truncatechars:17 }}</a></p>
</div>
<ul>
<li><a href="/logout">Выйти</a></li>
</ul>
{% else %}
<ul>
<li><a href="/register">Регистрация</a></li>
<li><a href="/login">Авторизация</a></li>
</ul>
{% endif %}
</header>
<div class="wrapper">
{% block content %}
{% endblock %}
</div>
</body>
</html>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment