Skip to content

Commit

Permalink
Add related_name to user field in AlbumImage model and update related…
Browse files Browse the repository at this point in the history
… files

The related_name attribute 'album_images' was added to the user foreign key in the AlbumImage model in models.py. This change required generating a new migration file, 0004_alter_albumimage_user.py. Additionally, corresponding updates were made in schema.py and users/types.py files to handle this new related_name attribute.
  • Loading branch information
catgirlinspace committed Jun 8, 2024
1 parent ec582a4 commit 8adf8c0
Show file tree
Hide file tree
Showing 4 changed files with 29 additions and 3 deletions.
21 changes: 21 additions & 0 deletions splatnet_album/migrations/0004_alter_albumimage_user.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,21 @@
# Generated by Django 5.0.6 on 2024-06-08 22:09

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


class Migration(migrations.Migration):

dependencies = [
('splatnet_album', '0003_albumimage_npln_image_id_and_more'),
migrations.swappable_dependency(settings.AUTH_USER_MODEL),
]

operations = [
migrations.AlterField(
model_name='albumimage',
name='user',
field=models.ForeignKey(on_delete=django.db.models.deletion.CASCADE, related_name='album_images', to=settings.AUTH_USER_MODEL),
),
]
2 changes: 1 addition & 1 deletion splatnet_album/models.py
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@ class AlbumImage(models.Model):
height = models.IntegerField()
width = models.IntegerField()
uploaded_at = models.DateTimeField(auto_now_add=True)
user = models.ForeignKey(User, on_delete=models.CASCADE)
user = models.ForeignKey(User, on_delete=models.CASCADE, related_name='album_images')

def __str__(self):
return f"@{self.user.username} - {self.npln_image_id}"
2 changes: 1 addition & 1 deletion splatnet_album/schema.py
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,7 @@

@strawberry.type(name="Query")
class SplatNetAlbumQuery:
userAlbum: ListConnectionWithTotalCount[AlbumImage] = strawberry_django.connection()
user_album: ListConnectionWithTotalCount[AlbumImage] = strawberry_django.connection()


def check_url(url):
Expand Down
7 changes: 6 additions & 1 deletion users/types.py
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
from typing import List
from typing import TYPE_CHECKING, Annotated

import strawberry.relay
import strawberry_django
Expand All @@ -8,6 +8,9 @@
from battles.types import Battle
from . import models

if TYPE_CHECKING:
from splatnet_album.types import AlbumImage


@strawberry_django.type(models.User)
class User(relay.Node):
Expand All @@ -18,3 +21,5 @@ class User(relay.Node):
x_battle_division: auto
profile_picture: auto
battles: ListConnectionWithTotalCount[Battle] = strawberry_django.connection()
album_images: ListConnectionWithTotalCount[
Annotated["AlbumImage", strawberry.lazy("splatnet_album.types")]] = strawberry_django.connection()

0 comments on commit 8adf8c0

Please sign in to comment.