Skip to content

update user model and registration url - #1

Open
pbezrukov wants to merge 2 commits into
masterfrom
Upgrade-User-Model
Open

update user model and registration url#1
pbezrukov wants to merge 2 commits into
masterfrom
Upgrade-User-Model

Conversation

@pbezrukov

Copy link
Copy Markdown
Owner

No description provided.

Comment thread posts/models.py Outdated
Comment thread posts/models.py Outdated
text = models.TextField()
created_at = models.DateTimeField(auto_now_add=True)
approved = models.BooleanField(default=False)
user = models.ForeignKey(User, on_delete=models.CASCADE, default=1)

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

this field should be required and there should be no default here. I can't imagine a situation how a post could be created without a user.

Comment thread users/admin.py Outdated
@@ -0,0 +1,3 @@
from django.contrib import admin

# Register your models here.

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Do you really need this comment?

Comment thread users/models.py Outdated
from django.db import models
from django.core import validators
from django.contrib.auth.models import AbstractBaseUser, UserManager
# from django.contrib.auth.models import PermissionsMixin

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

remove commented out code

Comment thread users/models.py Outdated
validators=[validators.validate_email],
unique=True,
blank=False
)

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

overindented line

Comment thread users/models.py
objects = UserManager()

def __str__(self):
return self.username

@mvoitko mvoitko Sep 16, 2021

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

consider adding more unique fields to identify user. Are you sure this works? I guess it should be smth like f"{self.username}"

Comment thread users/serializers.py Outdated

class Meta:
model = User
fields = ('email', 'username', 'password',)

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

why do you need comma at the end in a tuple with more than 1 item?

Comment thread users/tests.py Outdated
@@ -0,0 +1,3 @@
from django.test import TestCase

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Remove this file until you add tests

]

operations = [
migrations.AddField(

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

consider merging this to the initial migration

Comment thread users/migrations/0001_initial.py Outdated
@@ -0,0 +1,32 @@
# Generated by Django 3.1.6 on 2021-06-01 22:41

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

why not have all migrations in one module?

Comment thread users/views.py
serializer.save()

return Response(
status=status.HTTP_201_CREATED,

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

consider responding with user_id and maybe even all her data

Comment thread Dockerfile
@@ -0,0 +1,8 @@
FROM python:3.7-stretch

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

consider using more fresh python

Comment thread Dockerfile
@@ -0,0 +1,8 @@
FROM python:3.7-stretch
RUN apt-get update
RUN apt-get upgrade -y

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

It's better not to upgrade distribution

Comment thread Dockerfile
@@ -0,0 +1,8 @@
FROM python:3.7-stretch
RUN apt-get update

@mvoitko mvoitko Sep 21, 2021

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

  1. add --yes flag
  2. Remove cache with rm -rf /var/lib/apt/lists/*
  3. Why do you need update if there is no installation here.

Comment thread Dockerfile
RUN apt-get upgrade -y
COPY ./ /
WORKDIR ./
RUN pip3 install --no-cache-dir -r requirements.txt && \

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

use specific pip version

Comment thread Dockerfile
RUN apt-get update
RUN apt-get upgrade -y
COPY ./ /
WORKDIR ./

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Specify workdir explicitly

Comment thread docker-compose.yml
app:
container_name: app
build: .
command: bash -c "python manage.py makemigrations && python manage.py migrate && python manage.py runserver 0.0.0.0:8000"

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

If you have more than 1 command it's better to have them in entrypoint.sh file with appropriate linting. It would be easier to maintain and read

Comment thread redit/settings.py
'USER': 'user',
'PASSWORD': 'password',
'HOST': '127.0.0.1',
'HOST': 'db',

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This all should be read from env vars

Comment thread users/models.py


class User(AbstractBaseUser):

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

no need in empty line here. Consider adding linting and type checking configs in setup.cfg

Comment thread Dockerfile
FROM python:3.7-stretch
RUN apt-get update
RUN apt-get upgrade -y
COPY ./ /

@mvoitko mvoitko Sep 21, 2021

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Consider adding

ENV DEBIAN_FRONTEND=noninteractive
# Keeps Python from generating .pyc files in the container
ENV PYTHONDONTWRITEBYTECODE 1
# Prevents Python from buffering stdout and stderr
ENV PYTHONUNBUFFERED 1

Comment thread Dockerfile
WORKDIR ./
RUN pip3 install --no-cache-dir -r requirements.txt && \
rm -v requirements.txt
EXPOSE 8000

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Consider adding:

COPY scripts/entrypoint.sh /app/scripts/entrypoint.sh

ENTRYPOINT ["./scripts/entrypoint.sh"]

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants