#ARC-60 add mptt and migrations

remotes/origin/PR-39
Mukhtar 9 years ago
parent 002c17bbe9
commit bb6e889589
  1. 7
      projects/admin.py
  2. 22
      projects/forms.py
  3. 53
      projects/migrations/0043_auto_20160921_2324.py
  4. 22
      projects/migrations/0044_auto_20160921_2353.py
  5. 22
      projects/migrations/0045_auto_20160922_0039.py
  6. 9
      projects/models.py
  7. 17
      projects/templates/customer_project_create.html
  8. 1
      users/forms.py
  9. 4
      users/templates/worksell_create_form.html
  10. 10
      work_sell/forms.py
  11. 22
      work_sell/migrations/0017_auto_20160922_0057.py
  12. 2
      work_sell/models.py

@ -1,5 +1,6 @@
from django import forms from django import forms
from django.contrib import admin from django.contrib import admin
from mptt.admin import MPTTModelAdmin
from .models import ( from .models import (
Answer, Answer,
@ -18,6 +19,10 @@ from .models import (
) )
class BuildingClassficationAdmin(MPTTModelAdmin):
readonly_fields = ('pk', 'lft', 'rght', 'tree_id', 'level')
class ProjectAdminForm(forms.ModelForm): class ProjectAdminForm(forms.ModelForm):
files = forms.ModelMultipleChoiceField(queryset=ProjectFile.objects.none(), required=False) files = forms.ModelMultipleChoiceField(queryset=ProjectFile.objects.none(), required=False)
@ -44,7 +49,7 @@ class StageAdmin(admin.ModelAdmin):
admin.site.register(Answer) admin.site.register(Answer)
admin.site.register(Arbitration) admin.site.register(Arbitration)
admin.site.register(BuildingClassfication) admin.site.register(BuildingClassfication,BuildingClassficationAdmin)
admin.site.register(Candidate) admin.site.register(Candidate)
admin.site.register(ConstructionType) admin.site.register(ConstructionType)
admin.site.register(Order, OrderAdmin) admin.site.register(Order, OrderAdmin)

@ -6,7 +6,11 @@ from pprint import pprint, pformat
import itertools import itertools
import pydash as _; _.map = _.map_; _.filter = _.filter_ import pydash as _; _.map = _.map_; _.filter = _.filter_
from .models import Project, ProjectFile, Portfolio, Answer, AnswerMessage, Realty, PortfolioPhoto, Stage, ProjectWorkTypeSuggestion from .models import (
Project, ProjectFile, Portfolio, Answer,
AnswerMessage, Realty, PortfolioPhoto, Stage,
ProjectWorkTypeSuggestion, BuildingClassfication
)
from archilance import util from archilance import util
from common.models import Location, LiveImageUpload from common.models import Location, LiveImageUpload
from specializations.models import Specialization from specializations.models import Specialization
@ -145,6 +149,9 @@ class CustomerProjectEditForm(forms.ModelForm):
class RealtyForm(forms.ModelForm): class RealtyForm(forms.ModelForm):
building_classification = TreeNodeChoiceField(BuildingClassfication.objects.all(),
widget=forms.Select(attrs={'class': 'selectpicker'}))
class Meta: class Meta:
model = Realty model = Realty
@ -157,7 +164,6 @@ class RealtyForm(forms.ModelForm):
widgets = { widgets = {
'construction_type': forms.Select(attrs={'class': 'selectpicker'}), 'construction_type': forms.Select(attrs={'class': 'selectpicker'}),
'building_classification': forms.Select(attrs={'class': 'selectpicker'}),
} }
def __init__(self, *args, **kwargs): def __init__(self, *args, **kwargs):
@ -168,10 +174,15 @@ class RealtyForm(forms.ModelForm):
self.fields['name'].required = False self.fields['name'].required = False
self.fields['location'].queryset = Location.objects.root_nodes()[0].get_descendants() self.fields['location'].queryset = Location.objects.root_nodes()[0].get_descendants()
self.fields['building_classification'].queryset = BuildingClassfication.objects.root_nodes()[0].get_descendants()
# self.fields['location'].queryset = Location.objects # Migrate with this enabled # self.fields['location'].queryset = Location.objects # Migrate with this enabled
class PortfolioForm(forms.ModelForm): class PortfolioForm(forms.ModelForm):
building_classification = TreeNodeChoiceField(
BuildingClassfication.objects.exclude(name='_root'),
widget=forms.Select(attrs={'class': 'selectpicker'}),
)
duplicate = forms.BooleanField(required=False, label='Some label here') duplicate = forms.BooleanField(required=False, label='Some label here')
images_ids = forms.CharField(required=True) images_ids = forms.CharField(required=True)
@ -180,7 +191,6 @@ class PortfolioForm(forms.ModelForm):
fields = '__all__' fields = '__all__'
widgets = { widgets = {
'building_classification': forms.Select(attrs={'class': 'selectpicker'}),
'construction_type': forms.Select(attrs={'class': 'selectpicker'}), 'construction_type': forms.Select(attrs={'class': 'selectpicker'}),
'currency': forms.Select(attrs={'class': 'selectpicker'}), 'currency': forms.Select(attrs={'class': 'selectpicker'}),
'term_type': forms.Select(attrs={'class': 'selectpicker'}), 'term_type': forms.Select(attrs={'class': 'selectpicker'}),
@ -201,6 +211,11 @@ class PortfolioEditForm(forms.ModelForm):
widget=forms.CheckboxSelectMultiple, widget=forms.CheckboxSelectMultiple,
required=False, required=False,
) )
building_classification = TreeNodeChoiceField(
BuildingClassfication.objects.exclude(name='_root'),
widget=forms.Select(attrs={'class': 'selectpicker'}),
)
class Meta: class Meta:
model = Portfolio model = Portfolio
@ -222,7 +237,6 @@ class PortfolioEditForm(forms.ModelForm):
widgets = { widgets = {
'construction_type': forms.Select(attrs={'class': 'selectpicker'}), 'construction_type': forms.Select(attrs={'class': 'selectpicker'}),
'building_classification': forms.Select(attrs={'class': 'selectpicker'}),
'currency': forms.Select(attrs={'class': 'selectpicker'}), 'currency': forms.Select(attrs={'class': 'selectpicker'}),
'term_type': forms.Select(attrs={'class': 'selectpicker'}), 'term_type': forms.Select(attrs={'class': 'selectpicker'}),
'work_type': forms.Select(attrs={'class': 'selectpicker -project-work-type-select-field'}), 'work_type': forms.Select(attrs={'class': 'selectpicker -project-work-type-select-field'}),

@ -0,0 +1,53 @@
# -*- coding: utf-8 -*-
# Generated by Django 1.9.7 on 2016-09-21 20:24
from __future__ import unicode_literals
from django.db import migrations, models
import django.db.models.deletion
import django.db.models.manager
import mptt.fields
class Migration(migrations.Migration):
dependencies = [
('projects', '0042_portfolio_work_type'),
]
operations = [
migrations.AlterModelManagers(
name='buildingclassfication',
managers=[
('_default_manager', django.db.models.manager.Manager()),
],
),
migrations.AddField(
model_name='buildingclassfication',
name='level',
field=models.PositiveIntegerField(db_index=True, default=0, editable=False),
preserve_default=False,
),
migrations.AddField(
model_name='buildingclassfication',
name='lft',
field=models.PositiveIntegerField(db_index=True, default=0, editable=False),
preserve_default=False,
),
migrations.AddField(
model_name='buildingclassfication',
name='parent',
field=mptt.fields.TreeForeignKey(blank=True, null=True, on_delete=django.db.models.deletion.CASCADE, related_name='children', to='projects.BuildingClassfication'),
),
migrations.AddField(
model_name='buildingclassfication',
name='rght',
field=models.PositiveIntegerField(db_index=True, default=0, editable=False),
preserve_default=False,
),
migrations.AddField(
model_name='buildingclassfication',
name='tree_id',
field=models.PositiveIntegerField(db_index=True, default=0, editable=False),
preserve_default=False,
),
]

@ -0,0 +1,22 @@
# -*- coding: utf-8 -*-
# Generated by Django 1.9.7 on 2016-09-21 20:53
from __future__ import unicode_literals
from django.db import migrations
import django.db.models.deletion
import mptt.fields
class Migration(migrations.Migration):
dependencies = [
('projects', '0043_auto_20160921_2324'),
]
operations = [
migrations.AlterField(
model_name='realty',
name='building_classification',
field=mptt.fields.TreeForeignKey(on_delete=django.db.models.deletion.CASCADE, related_name='realties', to='projects.BuildingClassfication'),
),
]

@ -0,0 +1,22 @@
# -*- coding: utf-8 -*-
# Generated by Django 1.9.7 on 2016-09-21 21:39
from __future__ import unicode_literals
from django.db import migrations
import django.db.models.deletion
import mptt.fields
class Migration(migrations.Migration):
dependencies = [
('projects', '0044_auto_20160921_2353'),
]
operations = [
migrations.AlterField(
model_name='portfolio',
name='building_classification',
field=mptt.fields.TreeForeignKey(blank=True, null=True, on_delete=django.db.models.deletion.CASCADE, related_name='portfolios', to='projects.BuildingClassfication'),
),
]

@ -5,7 +5,7 @@ from django.db.models import Q
from django.core.exceptions import ValidationError from django.core.exceptions import ValidationError
from django.utils import timezone from django.utils import timezone
from hitcount.models import HitCountMixin from hitcount.models import HitCountMixin
from mptt.models import TreeForeignKey from mptt.models import TreeForeignKey, MPTTModel
import pydash as _; _.map = _.map_; _.filter = _.filter_ import pydash as _; _.map = _.map_; _.filter = _.filter_
from users.models import User, Team from users.models import User, Team
@ -33,8 +33,9 @@ TERM_TYPE_MORPHS = {
} }
class BuildingClassfication(models.Model): class BuildingClassfication(MPTTModel):
name = models.CharField(max_length=255) name = models.CharField(max_length=255)
parent = TreeForeignKey('self', blank=True, null=True, related_name='children', db_index=True)
def __str__(self): def __str__(self):
return self.name return self.name
@ -56,7 +57,7 @@ class ConstructionType(models.Model):
class Realty(models.Model): class Realty(models.Model):
building_classification = models.ForeignKey(BuildingClassfication, related_name='realties') building_classification = TreeForeignKey(BuildingClassfication, related_name='realties')
construction_type = models.ForeignKey(ConstructionType, related_name='realties') construction_type = models.ForeignKey(ConstructionType, related_name='realties')
location = TreeForeignKey('common.Location', related_name='realties', null=True, blank=True) location = TreeForeignKey('common.Location', related_name='realties', null=True, blank=True)
name = models.CharField(max_length=255) name = models.CharField(max_length=255)
@ -319,7 +320,7 @@ class Candidate(models.Model):
class Portfolio(models.Model): class Portfolio(models.Model):
budget = models.DecimalField(max_digits=10, decimal_places=0, default=0, null=True, blank=True) budget = models.DecimalField(max_digits=10, decimal_places=0, default=0, null=True, blank=True)
building_classification = models.ForeignKey(BuildingClassfication, related_name='portfolios', null=True, blank=True) building_classification = TreeForeignKey(BuildingClassfication, related_name='portfolios', null=True, blank=True)
construction_type = models.ForeignKey(ConstructionType, related_name='portfolios', null=True, blank=True) construction_type = models.ForeignKey(ConstructionType, related_name='portfolios', null=True, blank=True)
created = models.DateTimeField(auto_now_add=True, auto_created=True) created = models.DateTimeField(auto_now_add=True, auto_created=True)
currency = models.CharField(max_length=20, default='rur', choices=CURRENCIES, null=True, blank=True) currency = models.CharField(max_length=20, default='rur', choices=CURRENCIES, null=True, blank=True)

@ -237,14 +237,15 @@
value="{{ realty_form.name.value }}"> value="{{ realty_form.name.value }}">
</div> </div>
<div class="col-lg-3"> <div class="col-lg-3">
<select {{ realty_form.building_classification }}
id="realtyBuildingClassificationId" {# <select#}
class="selectpicker" {# id="realtyBuildingClassificationId"#}
name="{{ realty_form.building_classification.html_name }}"> {# #}
{% for c in realty_form.building_classification.field.queryset %} {# name="{{ realty_form.building_classification.html_name }}">#}
<option value="{{ c.pk }}" {% if realty_form.building_classification.value|int == c.pk %}selected="selected"{% endif %}>{{ c.name }}</option> {# {% for c in realty_form.building_classification.field.queryset %}#}
{% endfor %} {# <option value="{{ c.pk }}" {% if realty_form.building_classification.value|int == c.pk %}selected="selected"{% endif %}>{{ c.name }}</option>#}
</select> {# {% endfor %}#}
{# </select>#}
</div> </div>
<div class="col-lg-3"> <div class="col-lg-3">
<select <select

@ -26,6 +26,7 @@ class ContractorResumeForm(forms.ModelForm):
'text', 'text',
) )
class ContractorResumeFilesForm(forms.ModelForm): class ContractorResumeFilesForm(forms.ModelForm):
class Meta: class Meta:
model = ContractorResumeFiles model = ContractorResumeFiles

@ -95,11 +95,11 @@
</div> </div>
<div class="polsF1 disTab"> <div class="polsF1 disTab">
<input type="hidden" name="{{ worksell_form.contractor.html_name }}" value="{{ request.user.pk }}" /> <input type="hidden" name="{{ worksell_form.contractor.html_name }}" value="{{ request.user.pk }}" >
</div> </div>
<div class="polsF1 disTab"> <div class="polsF1 disTab">
<input type="hidden" name="images-ids" id="upload-files-worksell-pk" /> <input type="hidden" name="images-ids" id="upload-files-worksell-pk" >
</div> </div>

@ -1,9 +1,11 @@
import itertools import itertools
from django import forms from django import forms
from mptt.forms import TreeNodeChoiceField
from common.models import Location, LiveImageUpload from common.models import Location, LiveImageUpload
from .models import WorkSell, WorkSellPhoto from .models import WorkSell, WorkSellPhoto
from specializations.models import Specialization from specializations.models import Specialization
from projects.models import BuildingClassfication
class ContractorWorkSellTrashForm(forms.Form): class ContractorWorkSellTrashForm(forms.Form):
@ -30,6 +32,11 @@ class WorkSellForm(forms.ModelForm):
widget=forms.CheckboxSelectMultiple, widget=forms.CheckboxSelectMultiple,
required=False, required=False,
) )
building_classification = TreeNodeChoiceField(
BuildingClassfication.objects.exclude(name='_root'),
widget=forms.Select(attrs={'class': 'selectpicker'}),
)
class Meta: class Meta:
model = WorkSell model = WorkSell
@ -38,7 +45,7 @@ class WorkSellForm(forms.ModelForm):
'building_classification', 'building_classification',
'construction_type', 'construction_type',
'specialization', 'specialization',
'contractor',
'budget', 'budget',
'currency', 'currency',
'description', 'description',
@ -49,7 +56,6 @@ class WorkSellForm(forms.ModelForm):
) )
widgets = { widgets = {
'building_classification': forms.Select(attrs={'class': 'selectpicker'}),
'construction_type': forms.Select(attrs={'class': 'selectpicker'}), 'construction_type': forms.Select(attrs={'class': 'selectpicker'}),
'currency': forms.Select(attrs={'class': 'selectpicker'}), 'currency': forms.Select(attrs={'class': 'selectpicker'}),
'term_type': forms.Select(attrs={'class': 'selectpicker'}), 'term_type': forms.Select(attrs={'class': 'selectpicker'}),

@ -0,0 +1,22 @@
# -*- coding: utf-8 -*-
# Generated by Django 1.9.7 on 2016-09-21 21:57
from __future__ import unicode_literals
from django.db import migrations
import django.db.models.deletion
import mptt.fields
class Migration(migrations.Migration):
dependencies = [
('work_sell', '0016_worksell_work_type'),
]
operations = [
migrations.AlterField(
model_name='worksell',
name='building_classification',
field=mptt.fields.TreeForeignKey(blank=True, null=True, on_delete=django.db.models.deletion.CASCADE, related_name='worksells', to='projects.BuildingClassfication'),
),
]

@ -12,7 +12,7 @@ class WorkSell(models.Model):
# TODO: Add consistency ("work_sell" vs "worksell"): # TODO: Add consistency ("work_sell" vs "worksell"):
budget = models.DecimalField(max_digits=10, decimal_places=0, default=0, null=True, blank=True) budget = models.DecimalField(max_digits=10, decimal_places=0, default=0, null=True, blank=True)
building_classification = models.ForeignKey(BuildingClassfication, related_name='worksells', null=True, blank=True) building_classification = TreeForeignKey(BuildingClassfication, related_name='worksells', null=True, blank=True)
construction_type = models.ForeignKey(ConstructionType, related_name='worksells', null=True, blank=True) construction_type = models.ForeignKey(ConstructionType, related_name='worksells', null=True, blank=True)
contractor = models.ForeignKey(User, related_name='work_sell', null=True, blank=True) # TODO: Pluralize related name contractor = models.ForeignKey(User, related_name='work_sell', null=True, blank=True) # TODO: Pluralize related name
created = models.DateTimeField(auto_now_add=True) created = models.DateTimeField(auto_now_add=True)

Loading…
Cancel
Save