-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
1 parent
1b34f79
commit 31d2302
Showing
69 changed files
with
13,961 additions
and
0 deletions.
There are no files selected for viewing
Empty file.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,6 @@ | ||
from django.contrib import admin | ||
|
||
from .models import Tag, Article | ||
|
||
admin.site.register(Tag) | ||
admin.site.register(Article) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,5 @@ | ||
from django.apps import AppConfig | ||
|
||
|
||
class ArticlesConfig(AppConfig): | ||
name = 'articles' |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,20 @@ | ||
from django import forms | ||
from .models import Tag | ||
from .models import Article | ||
|
||
''' | ||
class ArticleForm(forms.Form): | ||
name=forms.CharField(label = 'Название статьи', max_length = 100) | ||
text=forms.CharField(label = 'Текст статьи') | ||
tags=forms.ModelMultipleChoiceField(queryset=Tag.objects.all(), | ||
widget=forms.CheckboxSelectMultiple()) | ||
''' | ||
|
||
class ArticleForm(forms.ModelForm): | ||
article_name = forms.CharField(label = 'Название статьи') | ||
|
||
class Meta: | ||
model = Article | ||
fields = '__all__' | ||
# fields = ('article_name', 'article_text') | ||
# exclude = ('tags') |
Empty file.
Empty file.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,43 @@ | ||
from django.core.management.base import BaseCommand | ||
from articles.models import Article, Tag | ||
|
||
|
||
class Command(BaseCommand): | ||
|
||
def handle(self, *args, **options): | ||
|
||
|
||
|
||
# Запрос в базу без условия! | ||
print('DB command!') | ||
articles = Article.objects.all() | ||
print(type(articles), articles) | ||
for art in articles: | ||
print(f'Name: {art.article_name}, Text: {art.article_text}, Tags: {art.tag_number()}') | ||
|
||
#Запрос в базу c условием! | ||
# | ||
# # get | ||
# art_ = Article.objects.get(article_name = 'Happy lion') | ||
# print(art_) | ||
# # filter | ||
# tags = Tag.objects.filter(tag_name = 'nature') | ||
# print(tags) | ||
# | ||
# # Связанные поля | ||
# print(art_.article_tag.all()) | ||
# print(art_.article_tag.first()) | ||
# | ||
# | ||
# # Добавление в БД | ||
# Tag.objects.create(tag_name = 'Travelling') | ||
# tags = Tag.objects.all() | ||
# print(tags) | ||
# | ||
# # Удаление | ||
# tag = Tag.objects.filter(tag_name='Travelling') | ||
# tag.delete() | ||
|
||
|
||
tags = Tag.objects.all() | ||
print(tags) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,8 @@ | ||
from django.core.management.base import BaseCommand | ||
|
||
|
||
class Command(BaseCommand): | ||
|
||
def handle(self, *args, **options): | ||
|
||
print('Hello!') |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,33 @@ | ||
# Generated by Django 3.0.3 on 2020-03-17 09:11 | ||
|
||
import datetime | ||
from django.db import migrations, models | ||
|
||
|
||
class Migration(migrations.Migration): | ||
|
||
initial = True | ||
|
||
dependencies = [ | ||
] | ||
|
||
operations = [ | ||
migrations.CreateModel( | ||
name='Tag', | ||
fields=[ | ||
('id', models.AutoField(auto_created=True, primary_key=True, serialize=False, verbose_name='ID')), | ||
('tag_name', models.CharField(max_length=100)), | ||
], | ||
), | ||
migrations.CreateModel( | ||
name='Article', | ||
fields=[ | ||
('id', models.AutoField(auto_created=True, primary_key=True, serialize=False, verbose_name='ID')), | ||
('article_name', models.CharField(max_length=100, null=True)), | ||
('article_text', models.CharField(max_length=1000, null=True)), | ||
('article_date', models.DateTimeField(default=datetime.datetime(2020, 3, 17, 9, 11, 35, 433347))), | ||
('article_img', models.ImageField(blank=True, null=True, upload_to='articles')), | ||
('article_tag', models.ManyToManyField(to='articles.Tag')), | ||
], | ||
), | ||
] |
Empty file.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,59 @@ | ||
from django.db import models | ||
from datetime import datetime | ||
import os | ||
from django.conf import settings | ||
|
||
# Create your models here. | ||
|
||
#https://djbook.ru/rel1.9/topics/db/models.html#model-inheritance - наследование моделей | ||
|
||
class Tag(models.Model, ): | ||
tag_name = models.CharField(max_length = 100) | ||
|
||
def __str__(self): | ||
return f'{self.tag_name}' | ||
|
||
class Article(models.Model): | ||
article_name = models.CharField(max_length = 100, null = True) | ||
article_text = models.CharField(max_length = 1000, null = True) | ||
article_date = models.DateTimeField(default = datetime.now()) | ||
article_tag = models.ManyToManyField(Tag) | ||
article_img = models.ImageField(upload_to = 'articles', null = True, blank = True) | ||
#, default = os.path.join(settings.MEDIA_ROOT,'articles','happy_lion.jpg') | ||
|
||
def tag_number(self): | ||
return len(self.article_tag.all()) | ||
|
||
|
||
def is_tag_one(self): | ||
if len(self.article_tag.all()) == 1: | ||
return True | ||
return False | ||
''' | ||
DataField - дата | ||
TimeField - время | ||
Числовые типы: | ||
IntegerField | ||
PositeveIntegerField | ||
FloatField | ||
Логические типы: | ||
BooleanField | ||
Байтовый тип: | ||
BinaryField | ||
Email: | ||
EmailField | ||
URL: | ||
URLField | ||
Image: | ||
ImageField | ||
''' | ||
|
||
def __str__(self): | ||
return f'{self.article_name}, published: {self.article_date}' | ||
|
Large diffs are not rendered by default.
Oops, something went wrong.
Oops, something went wrong.