updated hero model, add hero model fixture

This commit is contained in:
Alexander Karpov 2022-07-02 16:57:02 +03:00
parent b0b64f66fa
commit f2c741bb7f
8 changed files with 40 additions and 11 deletions

2
.gitignore vendored
View File

@ -1,6 +1,6 @@
.idea .idea
static/ static/
media/ media/uploads/
# Byte-compiled / optimized / DLL files # Byte-compiled / optimized / DLL files
__pycache__/ __pycache__/

View File

@ -11,6 +11,7 @@ DEV branch for backend for chess rpg game
### installation ### installation
```shell ```shell
$ python3 manage.py makemigrations & python3 manage.py migrate $ python3 manage.py makemigrations & python3 manage.py migrate
$ python3 manage.py loaddata media/dump_data/hero_model_fixture.json
$ docker run -p 6379:6379 -d redis:5 $ docker run -p 6379:6379 -d redis:5
``` ```

View File

@ -97,7 +97,7 @@ class Hero(models.Model):
added = models.DateTimeField(auto_now_add=True) added = models.DateTimeField(auto_now_add=True)
type = models.CharField(blank=False, choices=HeroTypes.choices, max_length=7) type = models.CharField(blank=False, choices=HeroTypes.choices, max_length=7)
model = models.ForeignKey("HeroModelSet", on_delete=models.CASCADE) model_f = models.ForeignKey("HeroModelSet", on_delete=models.CASCADE)
health = models.IntegerField( health = models.IntegerField(
validators=[MinValueValidator(1), MaxValueValidator(10)], blank=False validators=[MinValueValidator(1), MaxValueValidator(10)], blank=False
) )
@ -108,14 +108,8 @@ class Hero(models.Model):
validators=[MinValueValidator(1), MaxValueValidator(10)], blank=False validators=[MinValueValidator(1), MaxValueValidator(10)], blank=False
) )
def idle_img(self): def model(self):
return self.idle_img_f.image.url return self.model_f.model.url
def attack_img(self):
return self.attack_img_f.image.url
def die_img(self):
return self.die_img_f.image.url
def __str__(self): def __str__(self):
return f"{self.type} {self.player.name}" return f"{self.type} {self.player.name}"
@ -145,7 +139,7 @@ class Hero(models.Model):
class HeroModelSet(models.Model): class HeroModelSet(models.Model):
hero_type = models.CharField(blank=False, choices=HeroTypes.choices, max_length=7) hero_type = models.CharField(blank=False, choices=HeroTypes.choices, max_length=7)
model = models.ImageField(upload_to="uploads/") model = models.FileField(upload_to="uploads/")
def __str__(self): def __str__(self):
return f"{self.hero_type} model file" return f"{self.hero_type} model file"

BIN
media/dump_data/dump.jpg Normal file

Binary file not shown.

After

Width:  |  Height:  |  Size: 145 KiB

Binary file not shown.

After

Width:  |  Height:  |  Size: 145 KiB

Binary file not shown.

After

Width:  |  Height:  |  Size: 145 KiB

Binary file not shown.

After

Width:  |  Height:  |  Size: 145 KiB

View File

@ -0,0 +1,34 @@
[
{
"model": "game.heromodelset",
"pk": 1,
"fields": {
"hero_type": "KING",
"model": "dump_data/dump.jpg"
}
},
{
"model": "game.heromodelset",
"pk": 2,
"fields": {
"hero_type": "WARRIOR",
"model": "dump_data/dump_mx4zxHq.jpg"
}
},
{
"model": "game.heromodelset",
"pk": 3,
"fields": {
"hero_type": "ARCHER",
"model": "dump_data/dump_d6lH7IJ.jpg"
}
},
{
"model": "game.heromodelset",
"pk": 4,
"fields": {
"hero_type": "WIZARD",
"model": "dump_data/dump_1P13Svy.jpg"
}
}
]