# Path: diag_app/models.py
# class Vote(models.Model):
#     tech = models.ForeignKey(Tech)
#     solution = models.ForeignKey(Solution, related_name='votes')
#     value = models.IntegerField(default=1)
# 
# class Problem(models.Model):
#     title = models.CharField(max_length=65)
#     system = models.ForeignKey(System, related_name='problems')
#     description = models.TextField(max_length=500)
#     tech = models.ForeignKey(Tech, related_name='problems')
#     model = models.ForeignKey(Model)
#     posted = models.DateTimeField(auto_now=True)
# 
# class Solution(models.Model):
#     description = models.TextField(max_length=500)
#     time_required = models.FloatField(default=0)
#     parts_cost = models.DecimalField(max_digits=6, decimal_places=2)
#     problem = models.ForeignKey(Problem, related_name='solutions')
#     tech = models.ForeignKey(Tech, related_name='solutions')
#     posted = models.DateTimeField(auto_now=True)
#     score = models.IntegerField(default=0)
# 
# class Tech(models.Model):
#     experience = models.IntegerField(default=0)
#     job_title = models.CharField(max_length=25)
#     shop = models.CharField(max_length=25)
#     user = models.OneToOneField(User)
#     tech_rating = models.IntegerField(default=0)
# 
# class Rating(models.Model):
#     tech = models.ForeignKey(Tech)
#     value = models.IntegerField(default=5)
# 
# class System(models.Model):
#     name = models.CharField(max_length=25)
# 
# class Brand(models.Model):
#     name = models.CharField(max_length=25)
# 
#     def __repr__(self):
#         return str(self.name)
# 
# Path: diag_app/models.py
# class Model(models.Model):
#     name = models.CharField(max_length=40)
#     brand = models.ForeignKey(Brand)
#     year = models.IntegerField(default=0)
# 
#     def __repr__(self):
#         return str(self.name)
# 
# class Problem_Model(models.Model):
#     problem = models.ForeignKey(Problem)
#     model = models.ForeignKey(Model)
# 
# class Commit(models.Model):
#     solution = models.ForeignKey(Solution, related_name='commits')
#     tech = models.ForeignKey(Tech)
#     posted = models.DateTimeField(auto_now=True)
#     text = models.TextField(max_length=200)
# 
# class Notification(models.Model):
#     tech = models.ForeignKey(Tech, related_name='techs')
#     message = models.CharField(max_length=20)
#     # is this the best way to link notifications to events?
#     solution = models.ForeignKey(Solution, related_name='solution',null=True)
#     commit = models.ForeignKey(Commit, related_name='commit',null=True)
#     posted = models.DateTimeField(auto_now=True)


from .models import Vote, Problem, Solution, Tech, Rating, System, Brand
from .models import Model, Problem_Model, Commit, Notification
from django.contrib.auth.models import User
from rest_framework import serializers
from django.contrib.auth import login
    password = serializers.CharField(write_only=True)

    def create(self, validated_data):
        user = User.objects.create(
            username=validated_data['username'],
            email=validated_data['email']
            )
        user.set_password(validated_data['password'])
        user.save()
        return user

    class Meta:
        model = User
        fields = ['id', 'password', 'email', 'username']
        read_only_fields = ['is_staff', 'is_superuser', 'is_active',
                            'date_joined',]


class TechGetSerializer(serializers.ModelSerializer):
    user = UserSerializer(many=False, read_only=True)

    class Meta:
        model = Tech
        fields = ['id', 'experience', 'job_title', 'shop', 'user',
                  'tech_rating']


class TechPostSerializer(serializers.ModelSerializer):

    class Meta:

# Path: diag_app/models.py
# class Vote(models.Model):
#     tech = models.ForeignKey(Tech)
#     solution = models.ForeignKey(Solution, related_name='votes')
#     value = models.IntegerField(default=1)
# 
# class Problem(models.Model):
#     title = models.CharField(max_length=65)
#     system = models.ForeignKey(System, related_name='problems')
#     description = models.TextField(max_length=500)
#     tech = models.ForeignKey(Tech, related_name='problems')
#     model = models.ForeignKey(Model)
#     posted = models.DateTimeField(auto_now=True)
# 
# class Solution(models.Model):
#     description = models.TextField(max_length=500)
#     time_required = models.FloatField(default=0)
#     parts_cost = models.DecimalField(max_digits=6, decimal_places=2)
#     problem = models.ForeignKey(Problem, related_name='solutions')
#     tech = models.ForeignKey(Tech, related_name='solutions')
#     posted = models.DateTimeField(auto_now=True)
#     score = models.IntegerField(default=0)
# 
# class Tech(models.Model):
#     experience = models.IntegerField(default=0)
#     job_title = models.CharField(max_length=25)
#     shop = models.CharField(max_length=25)
#     user = models.OneToOneField(User)
#     tech_rating = models.IntegerField(default=0)
# 
# class Rating(models.Model):
#     tech = models.ForeignKey(Tech)
#     value = models.IntegerField(default=5)
# 
# class System(models.Model):
#     name = models.CharField(max_length=25)
# 
# class Brand(models.Model):
#     name = models.CharField(max_length=25)
# 
#     def __repr__(self):
#         return str(self.name)
# 
# Path: diag_app/models.py
# class Model(models.Model):
#     name = models.CharField(max_length=40)
#     brand = models.ForeignKey(Brand)
#     year = models.IntegerField(default=0)
# 
#     def __repr__(self):
#         return str(self.name)
# 
# class Problem_Model(models.Model):
#     problem = models.ForeignKey(Problem)
#     model = models.ForeignKey(Model)
# 
# class Commit(models.Model):
#     solution = models.ForeignKey(Solution, related_name='commits')
#     tech = models.ForeignKey(Tech)
#     posted = models.DateTimeField(auto_now=True)
#     text = models.TextField(max_length=200)
# 
# class Notification(models.Model):
#     tech = models.ForeignKey(Tech, related_name='techs')
#     message = models.CharField(max_length=20)
#     # is this the best way to link notifications to events?
#     solution = models.ForeignKey(Solution, related_name='solution',null=True)
#     commit = models.ForeignKey(Commit, related_name='commit',null=True)
#     posted = models.DateTimeField(auto_now=True)


# Path: diag_app/serializers.py
from .models import Vote, Problem, Solution, Tech, Rating, System, Brand
from .models import Model, Problem_Model, Commit, Notification
from django.contrib.auth.models import User
from rest_framework import serializers
from django.contrib.auth import login

    password = serializers.CharField(write_only=True)

    def create(self, validated_data):
        user = User.objects.create(
            username=validated_data['username'],
            email=validated_data['email']
            )
        user.set_password(validated_data['password'])
        user.save()
        return user

    class Meta:
        model = User
        fields = ['id', 'password', 'email', 'username']
        read_only_fields = ['is_staff', 'is_superuser', 'is_active',
                            'date_joined',]


class TechGetSerializer(serializers.ModelSerializer):
    user = UserSerializer(many=False, read_only=True)

    class Meta:
        model = Tech
        fields = ['id', 'experience', 'job_title', 'shop', 'user',
                  'tech_rating']


class TechPostSerializer(serializers.ModelSerializer):

    class Meta:

        model = Tech