Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 3 additions & 1 deletion .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -128,4 +128,6 @@ dmypy.json
.pyre/

#django media
media/
media/

*.jpg
2 changes: 1 addition & 1 deletion docker-compose.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@ version: '3'

services:
postgres:
image: postgres:13
image: postgis/postgis
volumes:
- database-data:/var/lib/postgresql/data/
ports:
Expand Down
18 changes: 17 additions & 1 deletion entertainment/admin.py
Original file line number Diff line number Diff line change
@@ -1,3 +1,19 @@
from django.contrib import admin

# Register your models here.
from django.contrib.gis.admin import OSMGeoAdmin
from .models import Place, Rate, Comment


@admin.register(Place)
class PlaceAdmin(OSMGeoAdmin):
list_display = ('name', 'location', 'address', 'image', 'type')

Choose a reason for hiding this comment

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

Suggested change
list_display = ('name', 'location', 'address', 'image', 'type')
list_display = ('name', 'location', 'address', 'image', 'type', )

Choose a reason for hiding this comment

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

Use black to evade '' and "" differences



@admin.register(Rate)
class RateAdmin(admin.ModelAdmin):
list_display = ("rating", "created_at", "user", "comment")

Choose a reason for hiding this comment

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

Suggested change
list_display = ("rating", "created_at", "user", "comment")
list_display = ("rating", "created_at", "user", "comment", )



@admin.register(Comment)
class CommentAdmin(admin.ModelAdmin):
list_display = ("text", "created_at",)
26 changes: 26 additions & 0 deletions entertainment/migrations/0001_initial.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,26 @@
# Generated by Django 4.0.2 on 2022-02-19 19:04

import django.contrib.gis.db.models.fields
from django.db import migrations, models


class Migration(migrations.Migration):

initial = True

dependencies = [
]

operations = [
migrations.CreateModel(
name='Place',
fields=[
('id', models.BigAutoField(auto_created=True, primary_key=True, serialize=False, verbose_name='ID')),
('name', models.CharField(max_length=255)),
('location', django.contrib.gis.db.models.fields.PointField(srid=4326)),
('address', models.CharField(max_length=255)),
('image', models.ImageField(blank=True, null=True, upload_to='')),
('type', models.CharField(choices=[('cafe', 'Cafe'), ('restaurant', 'Restaurant'), ('sport', 'Sport'), ('tech', 'tech'), ('shop', 'Shop')], default='cafe', max_length=20)),

Choose a reason for hiding this comment

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

Why max_length = 20, if longest choice is restaraunt which is 10 characters?

],
),
]
42 changes: 42 additions & 0 deletions entertainment/migrations/0002_comment_alter_place_type_rate.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,42 @@
# Generated by Django 4.0.2 on 2022-02-20 18:59

from django.conf import settings
from django.db import migrations, models
import django.db.models.deletion
import entertainment.models


class Migration(migrations.Migration):

dependencies = [
migrations.swappable_dependency(settings.AUTH_USER_MODEL),
('entertainment', '0001_initial'),
]

operations = [
migrations.CreateModel(
name='Comment',
fields=[
('id', models.BigAutoField(auto_created=True, primary_key=True, serialize=False, verbose_name='ID')),
('text', models.TextField()),
('created_at', models.DateField(auto_now_add=True)),
('related_comments', models.ManyToManyField(to='entertainment.Comment')),
],
),
migrations.AlterField(
model_name='place',
name='type',
field=models.CharField(choices=[('cafe', 'Cafe'), ('restaurant', 'Restaurant'), ('sport', 'Sport'), ('tech', 'Tech'), ('shop', 'Shop'), ('study', 'Study')], default='cafe', max_length=20),
),
migrations.CreateModel(
name='Rate',
fields=[
('id', models.BigAutoField(auto_created=True, primary_key=True, serialize=False, verbose_name='ID')),
('rating', models.PositiveSmallIntegerField()),
('created_at', models.DateField(auto_now_add=True)),
('comment', models.OneToOneField(null=True, on_delete=django.db.models.deletion.SET_NULL, to='entertainment.comment')),
('place', models.ForeignKey(on_delete=django.db.models.deletion.CASCADE, related_name='place', to='entertainment.place')),
('user', models.OneToOneField(on_delete=models.SET(entertainment.models.get_sentinel_user), related_name='user', to=settings.AUTH_USER_MODEL)),
],
),
]
18 changes: 18 additions & 0 deletions entertainment/migrations/0003_alter_comment_related_comments.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,18 @@
# Generated by Django 4.0.2 on 2022-02-20 19:06

from django.db import migrations, models


class Migration(migrations.Migration):

dependencies = [
('entertainment', '0002_comment_alter_place_type_rate'),
]

operations = [
migrations.AlterField(
model_name='comment',
name='related_comments',
field=models.ManyToManyField(blank=True, to='entertainment.Comment'),
),
]
19 changes: 19 additions & 0 deletions entertainment/migrations/0004_alter_rate_comment.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,19 @@
# Generated by Django 4.0.2 on 2022-02-20 19:08

from django.db import migrations, models
import django.db.models.deletion


class Migration(migrations.Migration):

dependencies = [
('entertainment', '0003_alter_comment_related_comments'),
]

operations = [
migrations.AlterField(
model_name='rate',
name='comment',
field=models.OneToOneField(blank=True, null=True, on_delete=django.db.models.deletion.SET_NULL, to='entertainment.comment'),
),
]
19 changes: 19 additions & 0 deletions entertainment/migrations/0005_alter_rate_place.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,19 @@
# Generated by Django 4.0.2 on 2022-02-20 19:22

from django.db import migrations, models
import django.db.models.deletion


class Migration(migrations.Migration):

dependencies = [
('entertainment', '0004_alter_rate_comment'),
]

operations = [
migrations.AlterField(
model_name='rate',
name='place',
field=models.ForeignKey(on_delete=django.db.models.deletion.CASCADE, related_name='ratings', to='entertainment.place'),
),
]
21 changes: 21 additions & 0 deletions entertainment/migrations/0006_alter_rate_user.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,21 @@
# Generated by Django 4.0.2 on 2022-02-26 15:39

from django.conf import settings
from django.db import migrations, models
import entertainment.models


class Migration(migrations.Migration):

dependencies = [
migrations.swappable_dependency(settings.AUTH_USER_MODEL),
('entertainment', '0005_alter_rate_place'),
]

operations = [
migrations.AlterField(
model_name='rate',
name='user',
field=models.ForeignKey(on_delete=models.SET(entertainment.models.get_sentinel_user), related_name='user', to=settings.AUTH_USER_MODEL),
),
]
19 changes: 19 additions & 0 deletions entertainment/migrations/0007_alter_rate_rating.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,19 @@
# Generated by Django 4.0.2 on 2022-02-26 15:47

from django.db import migrations, models
import entertainment.validators


class Migration(migrations.Migration):

dependencies = [
('entertainment', '0006_alter_rate_user'),
]

operations = [
migrations.AlterField(
model_name='rate',
name='rating',
field=models.PositiveSmallIntegerField(validators=[entertainment.validators.validate_rating]),
),
]
19 changes: 19 additions & 0 deletions entertainment/migrations/0008_alter_rate_unique_together.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,19 @@
# Generated by Django 4.0.2 on 2022-02-26 15:51

from django.conf import settings
from django.db import migrations


class Migration(migrations.Migration):

dependencies = [
migrations.swappable_dependency(settings.AUTH_USER_MODEL),
('entertainment', '0007_alter_rate_rating'),
]

operations = [
migrations.AlterUniqueTogether(
name='rate',
unique_together={('place', 'user')},
),
]
Original file line number Diff line number Diff line change
@@ -0,0 +1,23 @@
# Generated by Django 4.0.2 on 2022-02-26 16:21

from django.db import migrations, models


class Migration(migrations.Migration):

dependencies = [
('entertainment', '0008_alter_rate_unique_together'),
]

operations = [
migrations.AlterField(
model_name='comment',
name='created_at',
field=models.DateTimeField(auto_now_add=True),
),
migrations.AlterField(
model_name='rate',
name='created_at',
field=models.DateTimeField(auto_now_add=True),
),
]
Original file line number Diff line number Diff line change
@@ -0,0 +1,30 @@
# Generated by Django 4.0.2 on 2022-02-26 19:25

from django.conf import settings
from django.db import migrations, models
import entertainment.models


class Migration(migrations.Migration):

dependencies = [
migrations.swappable_dependency(settings.AUTH_USER_MODEL),
('entertainment', '0009_alter_comment_created_at_alter_rate_created_at'),
]

operations = [
migrations.AlterModelOptions(
name='comment',
options={'ordering': ['-created_at']},
),
migrations.AlterModelOptions(
name='rate',
options={'ordering': ['-created_at']},
),
migrations.AddField(
model_name='comment',
name='user',
field=models.ForeignKey(default=1, on_delete=models.SET(entertainment.models.get_sentinel_user), related_name='users_comment', to=settings.AUTH_USER_MODEL),
preserve_default=False,
),
]
17 changes: 17 additions & 0 deletions entertainment/migrations/0011_alter_comment_options.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,17 @@
# Generated by Django 4.0.2 on 2022-02-26 20:33

from django.db import migrations


class Migration(migrations.Migration):

dependencies = [
('entertainment', '0010_alter_comment_options_alter_rate_options_and_more'),
]

operations = [
migrations.AlterModelOptions(
name='comment',
options={'ordering': ['created_at']},
),
]
18 changes: 18 additions & 0 deletions entertainment/migrations/0012_alter_place_type.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,18 @@
# Generated by Django 4.0.2 on 2022-03-10 09:56

from django.db import migrations, models


class Migration(migrations.Migration):

dependencies = [
('entertainment', '0011_alter_comment_options'),
]

operations = [
migrations.AlterField(
model_name='place',
name='type',
field=models.CharField(default='shop', max_length=200),
),
]

Choose a reason for hiding this comment

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

Man, 12 migrations... There is squash option

45 changes: 43 additions & 2 deletions entertainment/models.py
Original file line number Diff line number Diff line change
@@ -1,3 +1,44 @@
from django.db import models
from django.contrib.gis.db import models

# Create your models here.
from django.contrib.auth import get_user_model

from entertainment.validators import validate_rating

User = get_user_model()


def get_sentinel_user():
return get_user_model().objects.get_or_create(username='deleted')[0]


class Place(models.Model):
name = models.CharField(max_length=255)
location = models.PointField()
address = models.CharField(max_length=255)
image = models.ImageField(null=True, blank=True)
type = models.CharField(
max_length=200,
default="shop",
)


class Comment(models.Model):
text = models.TextField()
created_at = models.DateTimeField(auto_now_add=True)
related_comments = models.ManyToManyField("self", symmetrical=False, blank=True)
user = models.ForeignKey(User, on_delete=models.SET(get_sentinel_user), related_name="users_comment")

class Meta:
ordering = ['created_at']


class Rate(models.Model):
rating = models.PositiveSmallIntegerField(validators=[validate_rating,])
created_at = models.DateTimeField(auto_now_add=True)
place = models.ForeignKey(Place, on_delete=models.CASCADE, related_name="ratings")
user = models.ForeignKey(User, on_delete=models.SET(get_sentinel_user), related_name="user")
comment = models.OneToOneField(Comment, on_delete=models.SET_NULL, null=True, blank=True)

class Meta:
unique_together = ["place", "user"]
ordering = ['-created_at']
Loading