-
Notifications
You must be signed in to change notification settings - Fork 0
Feature/api #1
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
base: main
Are you sure you want to change the base?
Feature/api #1
Changes from all commits
f127665
e5956bb
b5e2c6d
0fa9b5e
31458f1
3b1a842
d2aa036
35ff523
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -128,4 +128,6 @@ dmypy.json | |
.pyre/ | ||
|
||
#django media | ||
media/ | ||
media/ | ||
|
||
*.jpg |
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') | ||||||
|
||||||
|
||||||
@admin.register(Rate) | ||||||
class RateAdmin(admin.ModelAdmin): | ||||||
list_display = ("rating", "created_at", "user", "comment") | ||||||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more.
Suggested change
|
||||||
|
||||||
|
||||||
@admin.register(Comment) | ||||||
class CommentAdmin(admin.ModelAdmin): | ||||||
list_display = ("text", "created_at",) |
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)), | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe 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? |
||
], | ||
), | ||
] |
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)), | ||
], | ||
), | ||
] |
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'), | ||
), | ||
] |
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'), | ||
), | ||
] |
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'), | ||
), | ||
] |
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), | ||
), | ||
] |
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]), | ||
), | ||
] |
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, | ||
), | ||
] |
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']}, | ||
), | ||
] |
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), | ||
), | ||
] | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Man, 12 migrations... There is |
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'] |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
There was a problem hiding this comment.
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