From ef774ad3e398a0eb1a82efee01d4d65c3dc6c862 Mon Sep 17 00:00:00 2001 From: Mukhtar Date: Wed, 8 Jun 2016 16:19:53 +0300 Subject: [PATCH] Add realty models --- chat/migrations/0002_auto_20160608_1555.py | 19 ++++ projects/admin.py | 7 +- projects/forms.py | 8 +- .../migrations/0020_auto_20160608_1555.py | 96 ++++++++++++++++ .../migrations/0021_auto_20160608_1602.py | 31 ++++++ .../migrations/0022_auto_20160608_1605.py | 27 +++++ .../migrations/0023_auto_20160608_1609.py | 38 +++++++ projects/models.py | 103 ++++++++++++------ 8 files changed, 291 insertions(+), 38 deletions(-) create mode 100644 chat/migrations/0002_auto_20160608_1555.py create mode 100644 projects/migrations/0020_auto_20160608_1555.py create mode 100644 projects/migrations/0021_auto_20160608_1602.py create mode 100644 projects/migrations/0022_auto_20160608_1605.py create mode 100644 projects/migrations/0023_auto_20160608_1609.py diff --git a/chat/migrations/0002_auto_20160608_1555.py b/chat/migrations/0002_auto_20160608_1555.py new file mode 100644 index 0000000..d990d75 --- /dev/null +++ b/chat/migrations/0002_auto_20160608_1555.py @@ -0,0 +1,19 @@ +# -*- coding: utf-8 -*- +# Generated by Django 1.9.6 on 2016-06-08 12:55 +from __future__ import unicode_literals + +from django.db import migrations + + +class Migration(migrations.Migration): + + dependencies = [ + ('chat', '0001_initial'), + ] + + operations = [ + migrations.AlterModelOptions( + name='message', + options={'verbose_name': 'Сообщение', 'verbose_name_plural': 'Сообщения'}, + ), + ] diff --git a/projects/admin.py b/projects/admin.py index 5fb5abb..0cff389 100644 --- a/projects/admin.py +++ b/projects/admin.py @@ -1,7 +1,8 @@ from django.contrib import admin from .models import Project, Portfolio, PortfolioPhoto, \ - Answer, Realty, Candidate, Order, Stage + Answer, Realty, Candidate, Order, Stage, Country, City,\ + BuildingClassfication, ConstructionType # class UserAdmin(admin.ModelAdmin): @@ -20,3 +21,7 @@ admin.site.register(Realty) admin.site.register(Order) admin.site.register(Candidate) admin.site.register(Stage) +admin.site.register(Country) +admin.site.register(City) +admin.site.register(BuildingClassfication) +admin.site.register(ConstructionType) diff --git a/projects/forms.py b/projects/forms.py index 415debe..dc90ee6 100644 --- a/projects/forms.py +++ b/projects/forms.py @@ -27,10 +27,10 @@ class RealtyForm(ModelForm): model = Realty fields = ( 'name', - 'building_classification', - 'type_construction', - 'country', - 'city', + # 'building_classification', + # 'construction_type', + # 'country', + # 'city', ) diff --git a/projects/migrations/0020_auto_20160608_1555.py b/projects/migrations/0020_auto_20160608_1555.py new file mode 100644 index 0000000..be0950b --- /dev/null +++ b/projects/migrations/0020_auto_20160608_1555.py @@ -0,0 +1,96 @@ +# -*- coding: utf-8 -*- +# Generated by Django 1.9.6 on 2016-06-08 12:55 +from __future__ import unicode_literals + +from django.conf import settings +from django.db import migrations, models +import django.db.models.deletion + + +class Migration(migrations.Migration): + + dependencies = [ + ('projects', '0019_auto_20160607_1916'), + ] + + operations = [ + migrations.CreateModel( + name='BuildingClassfication', + fields=[ + ('id', models.AutoField(auto_created=True, primary_key=True, serialize=False, verbose_name='ID')), + ('name', models.CharField(max_length=255)), + ], + options={ + 'verbose_name': 'Тип здания', + 'verbose_name_plural': 'Типы здания', + }, + ), + migrations.CreateModel( + name='City', + fields=[ + ('id', models.AutoField(auto_created=True, primary_key=True, serialize=False, verbose_name='ID')), + ('name', models.CharField(max_length=255)), + ], + options={ + 'verbose_name': 'Город', + 'verbose_name_plural': 'Города', + }, + ), + migrations.CreateModel( + name='ConstructionType', + fields=[ + ('id', models.AutoField(auto_created=True, primary_key=True, serialize=False, verbose_name='ID')), + ('name', models.CharField(max_length=255)), + ], + options={ + 'verbose_name': 'Вид строительства', + 'verbose_name_plural': 'Виды строительства', + }, + ), + migrations.CreateModel( + name='Country', + fields=[ + ('id', models.AutoField(auto_created=True, primary_key=True, serialize=False, verbose_name='ID')), + ('name', models.CharField(max_length=255)), + ], + options={ + 'verbose_name': 'Страна', + 'verbose_name_plural': 'Страны', + }, + ), + migrations.RemoveField( + model_name='realty', + name='type_construction', + ), + migrations.AlterField( + model_name='answer', + name='cost_type', + field=models.CharField(choices=[('rur', ''), ('usd', 'usd'), ('eur', 'eur')], default='rur', max_length=5), + ), + migrations.AlterField( + model_name='realty', + name='building_classification', + field=models.ForeignKey(on_delete=django.db.models.deletion.CASCADE, related_name='realties', to='projects.BuildingClassfication'), + ), + migrations.AlterField( + model_name='realty', + name='user', + field=models.ForeignKey(on_delete=django.db.models.deletion.CASCADE, related_name='realties', to=settings.AUTH_USER_MODEL), + ), + migrations.AlterField( + model_name='stage', + name='cost_type', + field=models.CharField(choices=[('rur', ''), ('usd', 'usd'), ('eur', 'eur')], default='rur', max_length=5), + ), + migrations.AddField( + model_name='city', + name='country', + field=models.ForeignKey(on_delete=django.db.models.deletion.CASCADE, related_name='cities', to='projects.Country'), + ), + migrations.AddField( + model_name='realty', + name='construction_type', + field=models.ForeignKey(default=None, on_delete=django.db.models.deletion.CASCADE, related_name='realties', to='projects.ConstructionType'), + preserve_default=False, + ), + ] diff --git a/projects/migrations/0021_auto_20160608_1602.py b/projects/migrations/0021_auto_20160608_1602.py new file mode 100644 index 0000000..c180d33 --- /dev/null +++ b/projects/migrations/0021_auto_20160608_1602.py @@ -0,0 +1,31 @@ +# -*- coding: utf-8 -*- +# Generated by Django 1.9.6 on 2016-06-08 13:02 +from __future__ import unicode_literals + +from django.db import migrations + + +class Migration(migrations.Migration): + + dependencies = [ + ('projects', '0020_auto_20160608_1555'), + ] + + operations = [ + migrations.RemoveField( + model_name='realty', + name='building_classification', + ), + migrations.RemoveField( + model_name='realty', + name='city', + ), + migrations.RemoveField( + model_name='realty', + name='construction_type', + ), + migrations.RemoveField( + model_name='realty', + name='country', + ), + ] diff --git a/projects/migrations/0022_auto_20160608_1605.py b/projects/migrations/0022_auto_20160608_1605.py new file mode 100644 index 0000000..5967c9e --- /dev/null +++ b/projects/migrations/0022_auto_20160608_1605.py @@ -0,0 +1,27 @@ +# -*- coding: utf-8 -*- +# Generated by Django 1.9.6 on 2016-06-08 13:05 +from __future__ import unicode_literals + +from django.db import migrations, models + + +class Migration(migrations.Migration): + + dependencies = [ + ('projects', '0021_auto_20160608_1602'), + ] + + operations = [ + migrations.AddField( + model_name='realty', + name='building_classification', + field=models.CharField(default=None, max_length=255), + preserve_default=False, + ), + migrations.AddField( + model_name='realty', + name='construction_type', + field=models.CharField(default=None, max_length=255), + preserve_default=False, + ), + ] diff --git a/projects/migrations/0023_auto_20160608_1609.py b/projects/migrations/0023_auto_20160608_1609.py new file mode 100644 index 0000000..ec65622 --- /dev/null +++ b/projects/migrations/0023_auto_20160608_1609.py @@ -0,0 +1,38 @@ +# -*- coding: utf-8 -*- +# Generated by Django 1.9.6 on 2016-06-08 13:09 +from __future__ import unicode_literals + +from django.db import migrations, models +import django.db.models.deletion + + +class Migration(migrations.Migration): + + dependencies = [ + ('projects', '0022_auto_20160608_1605'), + ] + + operations = [ + migrations.AddField( + model_name='realty', + name='city', + field=models.CharField(default=None, max_length=50), + preserve_default=False, + ), + migrations.AddField( + model_name='realty', + name='country', + field=models.CharField(default=None, max_length=50), + preserve_default=False, + ), + migrations.AlterField( + model_name='realty', + name='building_classification', + field=models.ForeignKey(on_delete=django.db.models.deletion.CASCADE, related_name='realties', to='projects.BuildingClassfication'), + ), + migrations.AlterField( + model_name='realty', + name='construction_type', + field=models.ForeignKey(on_delete=django.db.models.deletion.CASCADE, related_name='realties', to='projects.ConstructionType'), + ), + ] diff --git a/projects/models.py b/projects/models.py index d5a9b55..db2bf8e 100644 --- a/projects/models.py +++ b/projects/models.py @@ -5,33 +5,70 @@ from django.utils import timezone from users.models import User from specializations.models import Specialization -COST_TYPE_CHOICES = ( - ('rur', 'rur'), +CURRENCIES = ( + ('rur', ''), ('usd', 'usd'), ('eur', 'eur'), ) -TERM_TYPE_CHOICES = ( +TERMS = ( ('hour', 'hour'), ('day', 'day'), ('month', 'month'), ) -BUILDING_CLASSIFICATION_CHOICES = ( +class BuildingClassfication(models.Model): + name = models.CharField(max_length=255) -) -TYPE_CONSTRUCTION_CHOICES = ( + def __str__(self): + return self.name -) + class Meta: + verbose_name = 'Тип здания' + verbose_name_plural = 'Типы здания' + + +class ConstructionType(models.Model): + name = models.CharField(max_length=255) + + def __str__(self): + return self.name + + class Meta: + verbose_name = 'Вид строительства' + verbose_name_plural = 'Виды строительства' + + +class Country(models.Model): + name = models.CharField(max_length=255) + + def __str__(self): + return self.name + + class Meta: + verbose_name = 'Страна' + verbose_name_plural = 'Страны' + + +class City(models.Model): + name = models.CharField(max_length=255) + country = models.ForeignKey(Country, related_name='cities') + + def __str__(self): + return self.name + + class Meta: + verbose_name = 'Город' + verbose_name_plural = 'Города' class Realty(models.Model): name = models.CharField(max_length=255) - building_classification = models.CharField(max_length=50) - type_construction = models.CharField(max_length=50) + building_classification = models.ForeignKey(BuildingClassfication, related_name='realties') + construction_type = models.ForeignKey(ConstructionType, related_name='realties') country = models.CharField(max_length=50) city = models.CharField(max_length=50) - user = models.ForeignKey(User, related_name='realty') + user = models.ForeignKey(User, related_name='realties') def __str__(self): return self.name @@ -42,11 +79,10 @@ class Realty(models.Model): class Project(models.Model): - TYPE_WORK_CHOICES = ( + WORK_TYPE = ( ('1', 'проектирование'), ('2', 'техническое сопровождение') ) - name = models.CharField(max_length=255) price = models.DecimalField(max_digits=10, decimal_places=0) specialization = models.ForeignKey(Specialization, related_name='projects') @@ -54,7 +90,7 @@ class Project(models.Model): user = models.ForeignKey(User, related_name='projects') budget = models.CharField(max_length=20, blank=True) cro = models.BooleanField(default=False) - type_work = models.CharField(max_length=20, choices=TYPE_WORK_CHOICES, default='1') + type_work = models.CharField(max_length=20, choices=WORK_TYPE, default='1') term_cost = models.BooleanField(default=False) secure_transaction = models.BooleanField(default=False) realty = models.ForeignKey(Realty, null=True, related_name='projects') @@ -68,6 +104,25 @@ class Project(models.Model): verbose_name_plural = 'Проекты' +class Answer(models.Model): + cost = models.DecimalField(max_digits=10, decimal_places=0) + cost_type = models.CharField(max_length=5, choices=CURRENCIES, default='rur') + text = models.TextField() + term = models.IntegerField(default=0) + term_type = models.CharField(max_length=10, choices=TERMS, default='hour') + project = models.ForeignKey(Project, related_name='answers') + user = models.ForeignKey(User, related_name='answers') + created = models.DateTimeField(default=timezone.now) + + def __str__(self): + return self.text + + class Meta: + verbose_name = 'Ответ к проекту' + verbose_name_plural = 'Ответы к проектам' + ordering = ('-created',) + + class Order(models.Model): project = models.OneToOneField(Project, related_name='order') contractor = models.ForeignKey(User, null=True, blank=True) @@ -87,9 +142,9 @@ class Stage(models.Model): name = models.CharField(max_length=255) result = models.CharField(max_length=255) cost = models.DecimalField(max_digits=10, decimal_places=0) - cost_type = models.CharField(max_length=5, choices=COST_TYPE_CHOICES, default='rur') + cost_type = models.CharField(max_length=5, choices=CURRENCIES, default='rur') term = models.IntegerField(default=0) - term_type = models.CharField(max_length=10, choices=TERM_TYPE_CHOICES, default='hour') + term_type = models.CharField(max_length=10, choices=TERMS, default='hour') order = models.ForeignKey(Order, related_name='stages') def __str__(self): @@ -100,24 +155,6 @@ class Stage(models.Model): verbose_name_plural = 'Этапы' -class Answer(models.Model): - cost = models.DecimalField(max_digits=10, decimal_places=0) - cost_type = models.CharField(max_length=5, choices=COST_TYPE_CHOICES, default='rur') - text = models.TextField() - term = models.IntegerField(default=0) - term_type = models.CharField(max_length=10, choices=TERM_TYPE_CHOICES, default='hour') - project = models.ForeignKey(Project, related_name='answers') - user = models.ForeignKey(User, related_name='answers') - created = models.DateTimeField(default=timezone.now) - - def __str__(self): - return self.text - - class Meta: - verbose_name = 'Ответ к проекту' - verbose_name_plural = 'Ответы к проектам' - ordering = ('-created',) - class Candidate(models.Model): answer = models.ForeignKey(Answer, related_name='candidates')