diff --git a/archilance/management/commands/generate_work_sells.py b/archilance/management/commands/generate_work_sells.py index 9992356..2b565b5 100644 --- a/archilance/management/commands/generate_work_sells.py +++ b/archilance/management/commands/generate_work_sells.py @@ -9,7 +9,7 @@ from archilance import util from common.models import Location from projects.models import TERM_TYPES, CURRENCIES, BuildingClassfication, ConstructionType from specializations.models import Specialization -from users.models import User +from users.models import User, Team from work_sell.models import WorkSell, WorkSellPhoto @@ -32,7 +32,11 @@ class Command(BaseCommand): ws.save() - ws.user = User.contractor_objects.order_by('?').first() + if _.sample((True, False)): + ws.contractor = User.contractor_objects.order_by('?').first() + else: + ws.team = Team.objects.order_by('?').first() + ws.building_classification = BuildingClassfication.objects.order_by('?').first() ws.construction_type = ConstructionType.objects.order_by('?').first() ws.location = Location.objects.root_nodes()[0].get_descendants().order_by('?').first() diff --git a/projects/migrations/0025_merge.py b/projects/migrations/0025_merge.py index 6a42e6a..2de8cd4 100644 --- a/projects/migrations/0025_merge.py +++ b/projects/migrations/0025_merge.py @@ -1,5 +1,5 @@ # -*- coding: utf-8 -*- -# Generated by Django 1.9.7 on 2016-09-02 07:45 +# Generated by Django 1.9.7 on 2016-09-02 15:04 from __future__ import unicode_literals from django.db import migrations @@ -8,8 +8,8 @@ from django.db import migrations class Migration(migrations.Migration): dependencies = [ - ('projects', '0024_auto_20160901_1247'), ('projects', '0024_auto_20160901_1548'), + ('projects', '0024_auto_20160901_1247'), ] operations = [ diff --git a/users/models.py b/users/models.py index 6eba910..391f71c 100644 --- a/users/models.py +++ b/users/models.py @@ -220,12 +220,16 @@ class User(AbstractBaseUser, PermissionsMixin): def get_popular_specialization(self): from ratings.models import SpecializationRating - # return SpecializationRating.objects.filter(user=self).order_by('position').first().specialization.name + + rating = SpecializationRating.objects.filter(user=self).order_by('position').first() + + if rating: + return rating.specialization.name class Team(models.Model): answers = GenericRelation('projects.Answer', related_query_name='teams') - avatar = models.ImageField(upload_to='teams/avatars/', blank=True) + avatar = models.ImageField(upload_to='teams/avatars/', blank=True) # TODO: Unused field? created = models.DateTimeField(default=timezone.now) name = models.CharField(max_length=255) owner = models.OneToOneField(User, related_name='team', blank=True, null=True) diff --git a/users/templates/contractor_office.html b/users/templates/contractor_office.html index 32e4f32..ade5edf 100644 --- a/users/templates/contractor_office.html +++ b/users/templates/contractor_office.html @@ -82,7 +82,7 @@

Состав группы

- {% for c in team_members %} + {% for c in contractor.team.contractors.all %}
{% if c.avatar %} @@ -114,7 +114,7 @@