Skip to content

Commit 28abf7f

Browse files
committed
add app for menu items.
add management command for create menu items.
1 parent af196a4 commit 28abf7f

11 files changed

Lines changed: 73 additions & 1 deletion

File tree

menu/__init__.py

Whitespace-only changes.

menu/admin.py

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,6 @@
1+
from django.contrib import admin
2+
3+
from menu.models import MenuItem
4+
5+
6+
admin.site.register(MenuItem)

menu/apps.py

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,5 @@
1+
from django.apps import AppConfig
2+
3+
4+
class MenuConfig(AppConfig):
5+
name = 'menu'

menu/factories.py

Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,13 @@
1+
import factory
2+
from factory.fuzzy import FuzzyChoice
3+
from cards_api.models import CardCategory
4+
5+
6+
class MenuFactory(factory.DjangoModelFactory):
7+
title = factory.Iterator(['Новости', 'События',
8+
'Записи', 'Блог', 'Вакансии'])
9+
card_category = FuzzyChoice(CardCategory.objects.all())
10+
url = factory.Faker('uri')
11+
12+
class Meta:
13+
model = 'menu.MenuItem'

menu/management/__init__.py

Whitespace-only changes.
Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,12 @@
1+
from django.core.management.base import BaseCommand, CommandError
2+
from menu import factories
3+
4+
5+
class Command(BaseCommand):
6+
help = 'Creates test menu items for development'
7+
8+
menu_items_count = 5
9+
10+
def handle(self, *args, **options):
11+
for _ in range(self.menu_items_count):
12+
factories.MenuFactory.create()

menu/migrations/0001_initial.py

Lines changed: 27 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,27 @@
1+
# -*- coding: utf-8 -*-
2+
# Generated by Django 1.11.3 on 2017-07-29 22:26
3+
from __future__ import unicode_literals
4+
5+
from django.db import migrations, models
6+
import django.db.models.deletion
7+
8+
9+
class Migration(migrations.Migration):
10+
11+
initial = True
12+
13+
dependencies = [
14+
('cards_api', '0002_auto_20170726_1045'),
15+
]
16+
17+
operations = [
18+
migrations.CreateModel(
19+
name='MenuItem',
20+
fields=[
21+
('id', models.AutoField(auto_created=True, primary_key=True, serialize=False, verbose_name='ID')),
22+
('title', models.CharField(max_length=512)),
23+
('url', models.URLField(blank=True, null=True)),
24+
('card_category', models.ForeignKey(blank=True, null=True, on_delete=django.db.models.deletion.CASCADE, to='cards_api.CardCategory')),
25+
],
26+
),
27+
]

menu/migrations/__init__.py

Whitespace-only changes.

menu/models.py

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,9 @@
1+
from django.db import models
2+
3+
4+
class MenuItem(models.Model):
5+
6+
title = models.CharField(max_length=512, blank=False)
7+
card_category = models.ForeignKey('cards_api.CardCategory',
8+
null=True, blank=True)
9+
url = models.URLField(null=True, blank=True)

python_ru/settings.py

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -21,6 +21,7 @@
2121
'banners',
2222
'cards_api',
2323
'subscribed_people',
24+
'menu',
2425
]
2526

2627
MIDDLEWARE = [

0 commit comments

Comments
 (0)