Filter list with db model
This commit is contained in:
1
.gitignore
vendored
1
.gitignore
vendored
@ -2,5 +2,4 @@
|
||||
/.vscode
|
||||
/.venv
|
||||
__pycache__
|
||||
/db.sqlite3
|
||||
/project/settings_local.py
|
||||
|
||||
BIN
db.sqlite3
Normal file
BIN
db.sqlite3
Normal file
Binary file not shown.
@ -3,4 +3,4 @@ from django.apps import AppConfig
|
||||
|
||||
class MainConfig(AppConfig):
|
||||
default_auto_field = "django.db.models.BigAutoField"
|
||||
name = "main"
|
||||
name = "project.main"
|
||||
|
||||
34
project/main/migrations/0001_initial.py
Normal file
34
project/main/migrations/0001_initial.py
Normal file
@ -0,0 +1,34 @@
|
||||
# Generated by Django 5.0.4 on 2024-05-14 20:16
|
||||
|
||||
from django.db import migrations, models
|
||||
|
||||
|
||||
class Migration(migrations.Migration):
|
||||
initial = True
|
||||
|
||||
dependencies = []
|
||||
|
||||
operations = [
|
||||
migrations.CreateModel(
|
||||
name="CatBreed",
|
||||
fields=[
|
||||
(
|
||||
"id",
|
||||
models.BigAutoField(
|
||||
auto_created=True,
|
||||
primary_key=True,
|
||||
serialize=False,
|
||||
verbose_name="ID",
|
||||
),
|
||||
),
|
||||
("name", models.CharField(max_length=100)),
|
||||
("country", models.CharField(max_length=100)),
|
||||
("origin", models.CharField(max_length=100)),
|
||||
("coat", models.CharField(max_length=100)),
|
||||
("pattern", models.CharField(max_length=100)),
|
||||
],
|
||||
options={
|
||||
"db_table": "cat_breeds",
|
||||
},
|
||||
),
|
||||
]
|
||||
@ -1,8 +1,10 @@
|
||||
from dataclasses import dataclass
|
||||
|
||||
from django.db import migrations
|
||||
|
||||
|
||||
@dataclass
|
||||
class CatBreed:
|
||||
class Breed:
|
||||
name: str
|
||||
country: str
|
||||
origin: str
|
||||
@ -11,672 +13,672 @@ class CatBreed:
|
||||
|
||||
|
||||
cat_breeds = [
|
||||
CatBreed(
|
||||
Breed(
|
||||
name="Abyssinian",
|
||||
country="Ethiopia",
|
||||
origin="Natural/Standard",
|
||||
coat="Short",
|
||||
pattern="Ticked",
|
||||
),
|
||||
CatBreed(
|
||||
Breed(
|
||||
name="Aegean",
|
||||
country="Greece",
|
||||
origin="Natural/Standard",
|
||||
coat="Semi-long",
|
||||
pattern="Bi- or tri-colored",
|
||||
),
|
||||
CatBreed(
|
||||
Breed(
|
||||
name="American Curl",
|
||||
country="United States",
|
||||
origin="Mutation",
|
||||
coat="Short/Long",
|
||||
pattern="All",
|
||||
),
|
||||
CatBreed(
|
||||
Breed(
|
||||
name="American Bobtail",
|
||||
country="United States",
|
||||
origin="Mutation",
|
||||
coat="Short/Long",
|
||||
pattern="All",
|
||||
),
|
||||
CatBreed(
|
||||
Breed(
|
||||
name="American Shorthair",
|
||||
country="United States",
|
||||
origin="Natural",
|
||||
coat="Short",
|
||||
pattern="All but colorpoint",
|
||||
),
|
||||
CatBreed(
|
||||
Breed(
|
||||
name="American Wirehair",
|
||||
country="United States",
|
||||
origin="Mutation",
|
||||
coat="Rex",
|
||||
pattern="All but colorpoint",
|
||||
),
|
||||
CatBreed(
|
||||
Breed(
|
||||
name="Arabian Mau",
|
||||
country="Arabian Peninsula",
|
||||
origin="Natural",
|
||||
coat="Short",
|
||||
pattern="",
|
||||
),
|
||||
CatBreed(
|
||||
Breed(
|
||||
name="Australian Mist",
|
||||
country="Australia",
|
||||
origin="Crossbreed",
|
||||
coat="Short",
|
||||
pattern="Spotted and Classic tabby",
|
||||
),
|
||||
CatBreed(
|
||||
Breed(
|
||||
name="Asian",
|
||||
country="United Kingdom",
|
||||
origin="",
|
||||
coat="Short",
|
||||
pattern="Evenly solid",
|
||||
),
|
||||
CatBreed(
|
||||
Breed(
|
||||
name="Asian Semi-longhair",
|
||||
country="United Kingdom",
|
||||
origin="Crossbreed",
|
||||
coat="Semi-long",
|
||||
pattern="Solid",
|
||||
),
|
||||
CatBreed(
|
||||
Breed(
|
||||
name="Balinese",
|
||||
country="United States",
|
||||
origin="Crossbreed",
|
||||
coat="Long",
|
||||
pattern="Colorpoint",
|
||||
),
|
||||
CatBreed(
|
||||
Breed(
|
||||
name="Bambino",
|
||||
country="United States",
|
||||
origin="Crossbreed",
|
||||
coat="Hairless/Furry down",
|
||||
pattern="",
|
||||
),
|
||||
CatBreed(
|
||||
Breed(
|
||||
name="Bengal",
|
||||
country="United States",
|
||||
origin="Hybrid",
|
||||
coat="Short",
|
||||
pattern="Spotted/Marbled",
|
||||
),
|
||||
CatBreed(
|
||||
Breed(
|
||||
name="Birman",
|
||||
country="France",
|
||||
origin="Natural",
|
||||
coat="Semi Long",
|
||||
pattern="Colorpoint",
|
||||
),
|
||||
CatBreed(
|
||||
Breed(
|
||||
name="Bombay",
|
||||
country="United States",
|
||||
origin="Crossbred",
|
||||
coat="Short",
|
||||
pattern="Solid",
|
||||
),
|
||||
CatBreed(
|
||||
Breed(
|
||||
name="Brazilian Shorthair",
|
||||
country="Brazil",
|
||||
origin="Natural",
|
||||
coat="Short",
|
||||
pattern="All",
|
||||
),
|
||||
CatBreed(
|
||||
Breed(
|
||||
name="British Semi-longhair",
|
||||
country="United Kingdom",
|
||||
origin="",
|
||||
coat="Medium",
|
||||
pattern="All",
|
||||
),
|
||||
CatBreed(
|
||||
Breed(
|
||||
name="British Shorthair",
|
||||
country="United Kingdom",
|
||||
origin="Natural",
|
||||
coat="Short",
|
||||
pattern="All",
|
||||
),
|
||||
CatBreed(
|
||||
Breed(
|
||||
name="British Longhair",
|
||||
country="United Kingdom",
|
||||
origin="",
|
||||
coat="Long",
|
||||
pattern="",
|
||||
),
|
||||
CatBreed(
|
||||
Breed(
|
||||
name="Burmese",
|
||||
country="Burma and Thailand",
|
||||
origin="Natural",
|
||||
coat="Short",
|
||||
pattern="Solid",
|
||||
),
|
||||
CatBreed(
|
||||
Breed(
|
||||
name="Burmilla",
|
||||
country="United Kingdom",
|
||||
origin="Crossbreed",
|
||||
coat="Short/Long",
|
||||
pattern="",
|
||||
),
|
||||
CatBreed(
|
||||
Breed(
|
||||
name="California Spangled",
|
||||
country="United States",
|
||||
origin="Crossbreed",
|
||||
coat="Short",
|
||||
pattern="Spotted",
|
||||
),
|
||||
CatBreed(
|
||||
Breed(
|
||||
name="Chantilly-Tiffany",
|
||||
country="United States",
|
||||
origin="",
|
||||
coat="",
|
||||
pattern="",
|
||||
),
|
||||
CatBreed(
|
||||
Breed(
|
||||
name="Chartreux",
|
||||
country="France",
|
||||
origin="Natural",
|
||||
coat="Short",
|
||||
pattern="Solid",
|
||||
),
|
||||
CatBreed(
|
||||
Breed(
|
||||
name="Chausie",
|
||||
country="France",
|
||||
origin="Hybrid",
|
||||
coat="Short",
|
||||
pattern="Ticked",
|
||||
),
|
||||
CatBreed(
|
||||
Breed(
|
||||
name="Cheetoh",
|
||||
country="United States",
|
||||
origin="Hybrid Crossbreed",
|
||||
coat="Short",
|
||||
pattern="Spotted",
|
||||
),
|
||||
CatBreed(
|
||||
Breed(
|
||||
name="Cornish Rex",
|
||||
country="United Kingdom",
|
||||
origin="Mutation",
|
||||
coat="Rex",
|
||||
pattern="All",
|
||||
),
|
||||
CatBreed(
|
||||
Breed(
|
||||
name="Cymric or Manx Longhair",
|
||||
country="United Kingdom",
|
||||
origin="Natural/Mutation",
|
||||
coat="Long",
|
||||
pattern="",
|
||||
),
|
||||
CatBreed(
|
||||
Breed(
|
||||
name="Cyprus",
|
||||
country="Cyprus",
|
||||
origin="Natural",
|
||||
coat="All",
|
||||
pattern="All",
|
||||
),
|
||||
CatBreed(
|
||||
Breed(
|
||||
name="Devon Rex",
|
||||
country="United Kingdom",
|
||||
origin="Mutation",
|
||||
coat="Rex",
|
||||
pattern="All",
|
||||
),
|
||||
CatBreed(
|
||||
Breed(
|
||||
name="Donskoy, or Don Sphynx",
|
||||
country="Russia",
|
||||
origin="",
|
||||
coat="Hairless",
|
||||
pattern="",
|
||||
),
|
||||
CatBreed(
|
||||
Breed(
|
||||
name="Dragon Li",
|
||||
country="China",
|
||||
origin="Natural",
|
||||
coat="Short",
|
||||
pattern="Striped tabby",
|
||||
),
|
||||
CatBreed(
|
||||
Breed(
|
||||
name="Dwarf cat, or Dwelf",
|
||||
country="",
|
||||
origin="Crossbreed",
|
||||
coat="",
|
||||
pattern="Hairless",
|
||||
),
|
||||
CatBreed(
|
||||
Breed(
|
||||
name="Egyptian Mau",
|
||||
country="Egypt",
|
||||
origin="Natural",
|
||||
coat="Short",
|
||||
pattern="Spotted",
|
||||
),
|
||||
CatBreed(
|
||||
Breed(
|
||||
name="European Shorthair",
|
||||
country="Finland and Sweden",
|
||||
origin="Natural",
|
||||
coat="Short",
|
||||
pattern="",
|
||||
),
|
||||
CatBreed(
|
||||
Breed(
|
||||
name="Exotic Shorthair",
|
||||
country="United States",
|
||||
origin="Crossbreed",
|
||||
coat="Short",
|
||||
pattern="All",
|
||||
),
|
||||
CatBreed(
|
||||
Breed(
|
||||
name="Foldex[4]",
|
||||
country="Canada",
|
||||
origin="Crossbreed",
|
||||
coat="Short",
|
||||
pattern="All",
|
||||
),
|
||||
CatBreed(
|
||||
Breed(
|
||||
name="German Rex",
|
||||
country="East Germany",
|
||||
origin="Mutation",
|
||||
coat="Rex",
|
||||
pattern="",
|
||||
),
|
||||
CatBreed(
|
||||
Breed(
|
||||
name="Havana Brown",
|
||||
country="United Kingdom",
|
||||
origin="",
|
||||
coat="Short",
|
||||
pattern="Solid",
|
||||
),
|
||||
CatBreed(
|
||||
Breed(
|
||||
name="Highlander",
|
||||
country="United States",
|
||||
origin="Crossbreed",
|
||||
coat="Short/Long",
|
||||
pattern="All",
|
||||
),
|
||||
CatBreed(
|
||||
Breed(
|
||||
name="Himalayan, or Colorpoint Persian",
|
||||
country="United States/United Kingdom",
|
||||
origin="Crossbreed",
|
||||
coat="Long",
|
||||
pattern="Colorpoint",
|
||||
),
|
||||
CatBreed(
|
||||
Breed(
|
||||
name="Japanese Bobtail",
|
||||
country="Japan",
|
||||
origin="Natural",
|
||||
coat="Short/Long",
|
||||
pattern="All but colorpoint and ticked",
|
||||
),
|
||||
CatBreed(
|
||||
Breed(
|
||||
name="Javanese",
|
||||
country="United States",
|
||||
origin="Crossbreed",
|
||||
coat="Long/Short",
|
||||
pattern="Colorpoint",
|
||||
),
|
||||
CatBreed(
|
||||
Breed(
|
||||
name="Karelian Bobtail",
|
||||
country="Western Russia",
|
||||
origin="Natural",
|
||||
coat="",
|
||||
pattern="",
|
||||
),
|
||||
CatBreed(
|
||||
Breed(
|
||||
name="Khao Manee",
|
||||
country="Thailand",
|
||||
origin="Natural",
|
||||
coat="Short",
|
||||
pattern="Solid",
|
||||
),
|
||||
CatBreed(
|
||||
Breed(
|
||||
name="Korat",
|
||||
country="Thailand",
|
||||
origin="Natural",
|
||||
coat="Short",
|
||||
pattern="Solid",
|
||||
),
|
||||
CatBreed(
|
||||
Breed(
|
||||
name="Korean Bobtail",
|
||||
country="Korea",
|
||||
origin="Natural",
|
||||
coat="Short/Long",
|
||||
pattern="Colorprint",
|
||||
),
|
||||
CatBreed(
|
||||
Breed(
|
||||
name="Korn Ja",
|
||||
country="Thailand",
|
||||
origin="Natural",
|
||||
coat="Short/Hairless",
|
||||
pattern="Solid",
|
||||
),
|
||||
CatBreed(
|
||||
Breed(
|
||||
name="Kurilian Bobtail, or Kuril Islands Bobtail",
|
||||
country="Eastern Russia,Japan",
|
||||
origin="Natural",
|
||||
coat="Short/Long",
|
||||
pattern="",
|
||||
),
|
||||
CatBreed(
|
||||
Breed(
|
||||
name="LaPerm",
|
||||
country="United States",
|
||||
origin="Mutation",
|
||||
coat="Rex",
|
||||
pattern="All",
|
||||
),
|
||||
CatBreed(
|
||||
Breed(
|
||||
name="Lykoi",
|
||||
country="United States",
|
||||
origin="Natural/Mutation",
|
||||
coat="Partly Hairless",
|
||||
pattern="Ticked",
|
||||
),
|
||||
CatBreed(
|
||||
Breed(
|
||||
name="Maine Coon",
|
||||
country="United States",
|
||||
origin="Natural",
|
||||
coat="Long",
|
||||
pattern="All but colorpoint and ticked",
|
||||
),
|
||||
CatBreed(
|
||||
Breed(
|
||||
name="Manx",
|
||||
country="United Kingdom",
|
||||
origin="Mutation",
|
||||
coat="Short/Long",
|
||||
pattern="All but colorpoint",
|
||||
),
|
||||
CatBreed(
|
||||
Breed(
|
||||
name="Mekong Bobtail",
|
||||
country="Russia",
|
||||
origin="Natural/Mutation",
|
||||
coat="Short",
|
||||
pattern="Colorpoint",
|
||||
),
|
||||
CatBreed(
|
||||
Breed(
|
||||
name="Minskin",
|
||||
country="United States",
|
||||
origin="Crossbreed",
|
||||
coat="Short/Hairless",
|
||||
pattern="All",
|
||||
),
|
||||
CatBreed(
|
||||
Breed(
|
||||
name="Munchkin",
|
||||
country="United States",
|
||||
origin="Mutation",
|
||||
coat="",
|
||||
pattern="",
|
||||
),
|
||||
CatBreed(
|
||||
Breed(
|
||||
name="Nebelung",
|
||||
country="United States",
|
||||
origin="",
|
||||
coat="Semi-long",
|
||||
pattern="Solid",
|
||||
),
|
||||
CatBreed(
|
||||
Breed(
|
||||
name="Napoleon",
|
||||
country="",
|
||||
origin="",
|
||||
coat="Long/short",
|
||||
pattern="Varied",
|
||||
),
|
||||
CatBreed(
|
||||
Breed(
|
||||
name="Norwegian Forest cat",
|
||||
country="Norway",
|
||||
origin="Natural",
|
||||
coat="Long",
|
||||
pattern="All but colorpoint",
|
||||
),
|
||||
CatBreed(
|
||||
Breed(
|
||||
name="Ocicat",
|
||||
country="United States",
|
||||
origin="Crossbreed",
|
||||
coat="Short",
|
||||
pattern="Spotted",
|
||||
),
|
||||
CatBreed(
|
||||
Breed(
|
||||
name="Ojos Azules",
|
||||
country="United States",
|
||||
origin="",
|
||||
coat="",
|
||||
pattern="",
|
||||
),
|
||||
CatBreed(
|
||||
Breed(
|
||||
name="Oregon Rex",
|
||||
country="United States",
|
||||
origin="Mutation",
|
||||
coat="Rex",
|
||||
pattern="",
|
||||
),
|
||||
CatBreed(
|
||||
Breed(
|
||||
name="Oriental Bicolor",
|
||||
country="",
|
||||
origin="",
|
||||
coat="",
|
||||
pattern="Bicolor",
|
||||
),
|
||||
CatBreed(
|
||||
Breed(
|
||||
name="Oriental Shorthair",
|
||||
country="",
|
||||
origin="",
|
||||
coat="Short",
|
||||
pattern="All but colorpoint",
|
||||
),
|
||||
CatBreed(
|
||||
Breed(
|
||||
name="Oriental Longhair",
|
||||
country="",
|
||||
origin="",
|
||||
coat="Semi-long",
|
||||
pattern="",
|
||||
),
|
||||
CatBreed(
|
||||
Breed(
|
||||
name="PerFoldæ(Experimental Breed - WCF),",
|
||||
country="Europe",
|
||||
origin="Crossbreed",
|
||||
coat="Long",
|
||||
pattern="All",
|
||||
),
|
||||
CatBreed(
|
||||
Breed(
|
||||
name="Persian (Modern Persian Cat),",
|
||||
country="Iran (Persia),",
|
||||
origin="Crossbreed",
|
||||
coat="Long",
|
||||
pattern="All",
|
||||
),
|
||||
CatBreed(
|
||||
Breed(
|
||||
name="Persian (Traditional Persian Cat),",
|
||||
country="Greater Iran",
|
||||
origin="Natural",
|
||||
coat="Long",
|
||||
pattern="All",
|
||||
),
|
||||
CatBreed(
|
||||
Breed(
|
||||
name="Peterbald",
|
||||
country="Russia",
|
||||
origin="Crossbreed",
|
||||
coat="Hairless",
|
||||
pattern="All",
|
||||
),
|
||||
CatBreed(
|
||||
Breed(
|
||||
name="Pixie-bob",
|
||||
country="United States",
|
||||
origin="Natural",
|
||||
coat="Short",
|
||||
pattern="Spotted",
|
||||
),
|
||||
CatBreed(
|
||||
Breed(
|
||||
name="Raas",
|
||||
country="Indonesia",
|
||||
origin="Natural",
|
||||
coat="Short",
|
||||
pattern="",
|
||||
),
|
||||
CatBreed(
|
||||
Breed(
|
||||
name="Ragamuffin",
|
||||
country="United States",
|
||||
origin="Crossbreed",
|
||||
coat="Long",
|
||||
pattern="All",
|
||||
),
|
||||
CatBreed(
|
||||
Breed(
|
||||
name="Ragdoll",
|
||||
country="United States",
|
||||
origin="Crossbreed",
|
||||
coat="Long",
|
||||
pattern="Colorpoint/Mitted/Bicolor",
|
||||
),
|
||||
CatBreed(
|
||||
Breed(
|
||||
name="Russian Blue",
|
||||
country="Russia",
|
||||
origin="Natural",
|
||||
coat="Short",
|
||||
pattern="Solid",
|
||||
),
|
||||
CatBreed(
|
||||
Breed(
|
||||
name="Russian White, Black and Tabby",
|
||||
country="Australia",
|
||||
origin="Crossbreed",
|
||||
coat="Short",
|
||||
pattern="",
|
||||
),
|
||||
CatBreed(
|
||||
Breed(
|
||||
name="Sam Sawet",
|
||||
country="Thailand",
|
||||
origin="Natural",
|
||||
coat="Short",
|
||||
pattern="Solid",
|
||||
),
|
||||
CatBreed(
|
||||
Breed(
|
||||
name="Savannah",
|
||||
country="United States",
|
||||
origin="Hybrid",
|
||||
coat="Short",
|
||||
pattern="Spotted",
|
||||
),
|
||||
CatBreed(
|
||||
Breed(
|
||||
name="Scottish Fold",
|
||||
country="United Kingdom",
|
||||
origin="Natural/Mutation",
|
||||
coat="Short/Long",
|
||||
pattern="All",
|
||||
),
|
||||
CatBreed(
|
||||
Breed(
|
||||
name="Selkirk Rex",
|
||||
country="United States",
|
||||
origin="Mutation/Cross",
|
||||
coat="Rex (Short/Long),",
|
||||
pattern="All",
|
||||
),
|
||||
CatBreed(
|
||||
Breed(
|
||||
name="Serengeti",
|
||||
country="United States",
|
||||
origin="Hybrid Crossbreed",
|
||||
coat="Short",
|
||||
pattern="Spotted",
|
||||
),
|
||||
CatBreed(
|
||||
Breed(
|
||||
name="Serrade petit",
|
||||
country="France",
|
||||
origin="Natural",
|
||||
coat="Short",
|
||||
pattern="",
|
||||
),
|
||||
CatBreed(
|
||||
Breed(
|
||||
name="Siamese",
|
||||
country="Thailand",
|
||||
origin="Natural",
|
||||
coat="Short",
|
||||
pattern="Colorpoint",
|
||||
),
|
||||
CatBreed(
|
||||
Breed(
|
||||
name="Siberian",
|
||||
country="Russia",
|
||||
origin="Natural",
|
||||
coat="Semi-long",
|
||||
pattern="All",
|
||||
),
|
||||
CatBreed(
|
||||
Breed(
|
||||
name="Singapura",
|
||||
country="Singapore",
|
||||
origin="Natural",
|
||||
coat="Short",
|
||||
pattern="Ticked",
|
||||
),
|
||||
CatBreed(
|
||||
Breed(
|
||||
name="Snowshoe",
|
||||
country="United States",
|
||||
origin="Crossbreed",
|
||||
coat="Short",
|
||||
pattern="Colorpoint",
|
||||
),
|
||||
CatBreed(
|
||||
Breed(
|
||||
name="Sokoke",
|
||||
country="Kenya",
|
||||
origin="Natural",
|
||||
coat="Short",
|
||||
pattern="Classic tabby with ticking",
|
||||
),
|
||||
CatBreed(
|
||||
Breed(
|
||||
name="Somali",
|
||||
country="Somalia",
|
||||
origin="Mutation",
|
||||
coat="Long",
|
||||
pattern="Ticked",
|
||||
),
|
||||
CatBreed(
|
||||
Breed(
|
||||
name="Sphynx",
|
||||
country="Canada",
|
||||
origin="Mutation",
|
||||
coat="Hairless",
|
||||
pattern="All",
|
||||
),
|
||||
CatBreed(
|
||||
Breed(
|
||||
name="Suphalak",
|
||||
country="Thailand",
|
||||
origin="Natural",
|
||||
coat="Short",
|
||||
pattern="Solid",
|
||||
),
|
||||
CatBreed(
|
||||
Breed(
|
||||
name="Thai",
|
||||
country="Thailand",
|
||||
origin="Natural",
|
||||
coat="Short",
|
||||
pattern="Colorpoint",
|
||||
),
|
||||
CatBreed(
|
||||
Breed(
|
||||
name="Thai Lilac",
|
||||
country="Thailand",
|
||||
origin="Natural",
|
||||
coat="Short",
|
||||
pattern="Solid",
|
||||
),
|
||||
CatBreed(
|
||||
Breed(
|
||||
name="Tonkinese",
|
||||
country="Canada",
|
||||
origin="Crossbreed",
|
||||
coat="Short",
|
||||
pattern="Colorpoint/Mink/Solid",
|
||||
),
|
||||
CatBreed(
|
||||
Breed(
|
||||
name="Toyger",
|
||||
country="United States",
|
||||
origin="Crossbreed",
|
||||
coat="Short",
|
||||
pattern="Mackerel",
|
||||
),
|
||||
CatBreed(
|
||||
Breed(
|
||||
name="Turkish Angora",
|
||||
country="Turkey",
|
||||
origin="Natural",
|
||||
coat="Semi-long",
|
||||
pattern="All but colorpoint",
|
||||
),
|
||||
CatBreed(
|
||||
Breed(
|
||||
name="Ukrainian Levkoy",
|
||||
country="Ukraine",
|
||||
origin="",
|
||||
coat="Hairless",
|
||||
pattern="",
|
||||
),
|
||||
CatBreed(
|
||||
Breed(
|
||||
name="York Chocolate",
|
||||
country="United States",
|
||||
origin="Natural",
|
||||
@ -684,3 +686,32 @@ cat_breeds = [
|
||||
pattern="Solid",
|
||||
),
|
||||
]
|
||||
|
||||
|
||||
def create_cat_breeds(apps, schema_editor):
|
||||
CatBreed = apps.get_model("main", "CatBreed")
|
||||
|
||||
bulk = []
|
||||
|
||||
for cat_breed in cat_breeds:
|
||||
bulk.append(
|
||||
CatBreed(
|
||||
name=cat_breed.name,
|
||||
country=cat_breed.country,
|
||||
origin=cat_breed.origin,
|
||||
coat=cat_breed.coat,
|
||||
pattern=cat_breed.pattern,
|
||||
)
|
||||
)
|
||||
|
||||
CatBreed.objects.bulk_create(bulk)
|
||||
|
||||
|
||||
class Migration(migrations.Migration):
|
||||
dependencies = [
|
||||
("main", "0001_initial"),
|
||||
]
|
||||
|
||||
operations = [
|
||||
migrations.RunPython(create_cat_breeds),
|
||||
]
|
||||
@ -1,3 +0,0 @@
|
||||
from django.db import models
|
||||
|
||||
# Create your models here.
|
||||
1
project/main/models/__init__.py
Normal file
1
project/main/models/__init__.py
Normal file
@ -0,0 +1 @@
|
||||
from .cat_breed import CatBreed
|
||||
12
project/main/models/cat_breed.py
Normal file
12
project/main/models/cat_breed.py
Normal file
@ -0,0 +1,12 @@
|
||||
from django.db import models
|
||||
|
||||
|
||||
class CatBreed(models.Model):
|
||||
name = models.CharField(max_length=100)
|
||||
country = models.CharField(max_length=100)
|
||||
origin = models.CharField(max_length=100)
|
||||
coat = models.CharField(max_length=100)
|
||||
pattern = models.CharField(max_length=100)
|
||||
|
||||
class Meta:
|
||||
db_table = "cat_breeds"
|
||||
@ -1,27 +1,31 @@
|
||||
from typing import Any, Optional
|
||||
|
||||
from project.main.cat_breeds import CatBreed, cat_breeds
|
||||
from django.db.models import Count, Q
|
||||
|
||||
from project.main.models import CatBreed
|
||||
from project.main.views.demo_view_base import DemoViewBase
|
||||
|
||||
|
||||
def get_countries() -> list[str]:
|
||||
return sorted(set([c.country for c in cat_breeds if len(c.country)]))
|
||||
ann = (
|
||||
CatBreed.objects.values("country")
|
||||
.annotate(Count("country"))
|
||||
.order_by("country")
|
||||
)
|
||||
return [a["country"] for a in ann]
|
||||
|
||||
|
||||
def filter_cat_breeds(
|
||||
breed_filter: Optional[str] = None, country_filter: Optional[str] = None
|
||||
) -> list[CatBreed]:
|
||||
if not breed_filter and not country_filter:
|
||||
return cat_breeds
|
||||
q = Q()
|
||||
|
||||
result = []
|
||||
for breed in cat_breeds:
|
||||
# if (not breed_filter or breed_filter.lower() in breed.name.lower()) or (
|
||||
# not country_filter or country_filter == breed.country
|
||||
# ):
|
||||
if not breed_filter or breed_filter.lower() in breed.name.lower():
|
||||
result.append(breed)
|
||||
return result
|
||||
if breed_filter:
|
||||
q &= Q(name__icontains=breed_filter)
|
||||
if country_filter:
|
||||
q &= Q(country=country_filter)
|
||||
|
||||
return CatBreed.objects.filter(q).order_by("name")
|
||||
|
||||
|
||||
class FilterListView(DemoViewBase):
|
||||
|
||||
@ -37,6 +37,7 @@ INSTALLED_APPS = [
|
||||
"django.contrib.sessions",
|
||||
"django.contrib.messages",
|
||||
"django.contrib.staticfiles",
|
||||
"project.main",
|
||||
]
|
||||
|
||||
MIDDLEWARE = [
|
||||
|
||||
Reference in New Issue
Block a user